This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] flesh out lto langhooks a bit more


The below patch fixes several common segfaults when processing LTO
objects.  We didn't initialize size_type_node (one would think
set_sizetype would do this for us, but apparently not...) and
lto_type_for_mode returned nonsensical answers 100% of the time.

With this patch, size_type_node is properly initialized and we return
nonsensical answers less than 100% of the time, which is usually enough
to get us to the first GC, where we fall over.

Committed to the LTO branch.

-Nathan

	* lto-lang.c (lto_type_for_mode): Move after lto_type_for_size.
	Implement for scalar integer modes.
	(lto_init): Initialize size_type_node.

Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 129458)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -65,17 +65,6 @@ lto_mark_addressable (tree t ATTRIBUTE_U
 }
 
 static tree
-lto_type_for_mode (enum machine_mode mode ATTRIBUTE_UNUSED, 
-		   int unsigned_p ATTRIBUTE_UNUSED)
-{
-  /* This hook is called by the middle-end.  For example,
-     assign_stack_local_1 uses this hook to determine whether
-     additional alignment is required for stack variables for which no
-     explicit alignment is provided.  */
-  return NULL_TREE;
-}
-
-static tree
 lto_type_for_size (unsigned precision ATTRIBUTE_UNUSED, 
 		   int unsignedp ATTRIBUTE_UNUSED)
 {
@@ -95,6 +84,20 @@ lto_type_for_size (unsigned precision AT
   return t;
 }
 
+static tree
+lto_type_for_mode (enum machine_mode mode ATTRIBUTE_UNUSED, 
+		   int unsigned_p ATTRIBUTE_UNUSED)
+{
+  /* This hook is called by the middle-end.  For example,
+     assign_stack_local_1 uses this hook to determine whether
+     additional alignment is required for stack variables for which no
+     explicit alignment is provided.  */
+  if (SCALAR_INT_MODE_P (mode))
+    return lto_type_for_size (GET_MODE_BITSIZE (mode), unsigned_p);
+  else
+    return NULL_TREE;
+}
+
 static int
 lto_global_bindings_p (void) 
 {
@@ -165,9 +168,15 @@ lto_init (void)
 			   /*signed_sizetype=*/false);
   /* Tell the middle end what type to use for the size of objects.  */
   if (strcmp (SIZE_TYPE, "unsigned int") == 0)
-    set_sizetype (unsigned_type_node);
+    {
+      set_sizetype (unsigned_type_node);
+      size_type_node = unsigned_type_node;
+    }
   else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
-    set_sizetype (long_unsigned_type_node);
+    {
+      set_sizetype (long_unsigned_type_node);
+      size_type_node = long_unsigned_type_node;
+    }
   else
     gcc_unreachable();
   /* Create other basic types.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]