[lto] Fix streaming of user asm names for builtins

Diego Novillo dnovillo@google.com
Sun May 31 15:57:00 GMT 2009


This patch fixes 8 failures in the builtins tests.  We were not
streaming asm names for builtins.

Jan, this patch affects some non-lto files.  I needed to move
set_builtin_user_assembler_name to builtins.c.  It should not
introduce many conflicts in your merged tree, however.

I've got a couple other patches in the pipeline.  But I'll try to
not touch common files.

Tested on x86_64.


2009-05-31  Diego Novillo  <dnovillo@google.com>

	* tree.h (set_builtin_user_assembler_name): Move from ...
	* c-common.h (set_builtin_user_assembler_name): ... here.
	* builtins.c (set_builtin_user_assembler_name): Move from ...
	* c-common.c (set_builtin_user_assembler_name): ... here.
	* lto-function-out.c (output_function_decl): Preserve
	user-set assembler names for builtins.
	* lto-function-in.c (input_function_decl): Call
	set_builtin_user_assembler_name if needed.

Index: tree.h
===================================================================
--- tree.h	(revision 148004)
+++ tree.h	(working copy)
@@ -4853,6 +4853,7 @@ extern bool is_builtin_name(const char*)
 extern int get_object_alignment (tree, unsigned int, unsigned int);
 extern tree fold_call_stmt (gimple, bool);
 extern tree gimple_fold_builtin_snprintf_chk (gimple, tree, enum built_in_function);
+extern void set_builtin_user_assembler_name (tree decl, const char *asmspec);
 
 /* In convert.c */
 extern tree strip_float_extensions (tree);
Index: builtins.c
===================================================================
--- builtins.c	(revision 148004)
+++ builtins.c	(working copy)
@@ -13824,3 +13824,41 @@ fold_call_stmt (gimple stmt, bool ignore
     }
   return NULL_TREE;
 }
+
+/* Look up the function in built_in_decls that corresponds to DECL
+   and set ASMSPEC as its user assembler name.  DECL must be a
+   function decl that declares a builtin.  */
+
+void
+set_builtin_user_assembler_name (tree decl, const char *asmspec)
+{
+  tree builtin;
+  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
+	      && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
+	      && asmspec != 0);
+
+  builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
+  set_user_assembler_name (builtin, asmspec);
+  switch (DECL_FUNCTION_CODE (decl))
+    {
+    case BUILT_IN_MEMCPY:
+      init_block_move_fn (asmspec);
+      memcpy_libfunc = set_user_assembler_libfunc ("memcpy", asmspec);
+      break;
+    case BUILT_IN_MEMSET:
+      init_block_clear_fn (asmspec);
+      memset_libfunc = set_user_assembler_libfunc ("memset", asmspec);
+      break;
+    case BUILT_IN_MEMMOVE:
+      memmove_libfunc = set_user_assembler_libfunc ("memmove", asmspec);
+      break;
+    case BUILT_IN_MEMCMP:
+      memcmp_libfunc = set_user_assembler_libfunc ("memcmp", asmspec);
+      break;
+    case BUILT_IN_ABORT:
+      abort_libfunc = set_user_assembler_libfunc ("abort", asmspec);
+      break;
+    default:
+      break;
+    }
+}
Index: lto-function-out.c
===================================================================
--- lto-function-out.c	(revision 148004)
+++ lto-function-out.c	(working copy)
@@ -2745,6 +2745,20 @@ output_function_decl (struct output_bloc
       output_global_record_start (ob, NULL, NULL, LTO_function_decl1);
       output_uleb128 (ob, DECL_BUILT_IN_CLASS (decl));
       output_uleb128 (ob, DECL_FUNCTION_CODE (decl));
+      if (DECL_ASSEMBLER_NAME_SET_P (decl))
+	{
+	  /* When the assembler name of a builtin gets a user name,
+	     the new name is always prefixed with '*' by
+	     set_builtin_user_assembler_name.  So, to prevent the
+	     reader side from adding a second '*', we omit it here.  */
+	  char *str = (char *) IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+	  if (strlen (str) > 1 && str[0] == '*')
+	    output_string (ob, ob->main_stream, &str[1]);
+	  else
+	    output_string (ob, ob->main_stream, NULL);
+	}
+      else
+	output_string (ob, ob->main_stream, NULL);
       LTO_DEBUG_TOKEN ("end_function_decl");
       return;
     }
Index: lto-function-in.c
===================================================================
--- lto-function-in.c	(revision 148004)
+++ lto-function-in.c	(working copy)
@@ -2719,6 +2719,7 @@ input_function_decl (struct lto_input_bl
 	 the code and class.  */
       enum built_in_class fclass;
       enum built_in_function fcode;
+      const char *asmname;
 
       fclass = (enum built_in_class) lto_input_uleb128 (ib);
       gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
@@ -2729,6 +2730,10 @@ input_function_decl (struct lto_input_bl
       decl = built_in_decls[(size_t) fcode];
       gcc_assert (decl);
 
+      asmname = input_string (data_in, ib);
+      if (asmname)
+	set_builtin_user_assembler_name (decl, asmname);
+
       global_vector_enter (data_in, decl);
 
       LTO_DEBUG_TOKEN ("end_function_decl");
Index: c-common.c
===================================================================
--- c-common.c	(revision 148004)
+++ c-common.c	(working copy)
@@ -5068,44 +5068,6 @@ c_common_nodes_and_builtins (void)
   memset (builtin_types, 0, sizeof (builtin_types));
 }
 
-/* Look up the function in built_in_decls that corresponds to DECL
-   and set ASMSPEC as its user assembler name.  DECL must be a
-   function decl that declares a builtin.  */
-
-void
-set_builtin_user_assembler_name (tree decl, const char *asmspec)
-{
-  tree builtin;
-  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
-	      && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
-	      && asmspec != 0);
-
-  builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
-  set_user_assembler_name (builtin, asmspec);
-  switch (DECL_FUNCTION_CODE (decl))
-    {
-    case BUILT_IN_MEMCPY:
-      init_block_move_fn (asmspec);
-      memcpy_libfunc = set_user_assembler_libfunc ("memcpy", asmspec);
-      break;
-    case BUILT_IN_MEMSET:
-      init_block_clear_fn (asmspec);
-      memset_libfunc = set_user_assembler_libfunc ("memset", asmspec);
-      break;
-    case BUILT_IN_MEMMOVE:
-      memmove_libfunc = set_user_assembler_libfunc ("memmove", asmspec);
-      break;
-    case BUILT_IN_MEMCMP:
-      memcmp_libfunc = set_user_assembler_libfunc ("memcmp", asmspec);
-      break;
-    case BUILT_IN_ABORT:
-      abort_libfunc = set_user_assembler_libfunc ("abort", asmspec);
-      break;
-    default:
-      break;
-    }
-}
-
 /* The number of named compound-literals generated thus far.  */
 static GTY(()) int compound_literal_number;
 
Index: c-common.h
===================================================================
--- c-common.h	(revision 148004)
+++ c-common.h	(working copy)
@@ -830,8 +830,6 @@ extern tree c_build_qualified_type (tree
    frontends.  */
 extern void c_common_nodes_and_builtins (void);
 
-extern void set_builtin_user_assembler_name (tree decl, const char *asmspec);
-
 extern void disable_builtin_function (const char *);
 
 extern void set_compound_literal_name (tree decl);



More information about the Gcc-patches mailing list