[LTO][PATCH] Fix non-whopr compilation ICE that can occur with new[]

Simon Baldwin simonb@google.com
Tue Jan 13 17:28:00 GMT 2009


This patch fixes an internal compiler error that can occur with non-whopr
compilations that involve new[] allocations of objects.  The patch undoes the
change of revision 136842, which introduced this error for non-whopr
compilation.

The problem that revision 136842 was intended to address is handled by the
later revision 137044, which augments reset_type_lang_specific to remove
all TYPE_SIZE[_UNIT] for array decls from the IR prior to LTO serialization.


gcc/cp/ChangeLog.lto
2009-01-13  Simon Baldwin  <simonb@google.com>

	* init.c (build_new_1): Remove nelts_for_type argument, and use
	only nelts.
	(build_new): Eliminate all uses of nelts_for_type.

gcc/testsuite/ChangeLog.lto
2009-01-13  Simon Baldwin  <simonb@google.com>

	* g++.dg/ipa/20090113-1.C: New.


Index: gcc/testsuite/g++.dg/ipa/20090113-1.C
===================================================================
--- gcc/testsuite/g++.dg/ipa/20090113-1.C	(revision 0)
+++ gcc/testsuite/g++.dg/ipa/20090113-1.C	(revision 0)
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O3"  } */
+
+struct S1 {
+ S1() { }
+};
+
+struct S2 {
+ int n;
+ S1* p;
+ void f() {
+   p = new S1[n = 1];
+ } 
+};
+
+struct S3 {
+ S2 s2;
+ void g() {
+   s2.f();
+ } 
+};
+
+void h() {
+ S3().g();
+}
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 143343)
+++ gcc/cp/init.c	(working copy)
@@ -1748,13 +1748,11 @@ avoid_placement_new_aliasing (tree t, tr
 /* Generate code for a new-expression, including calling the "operator
    new" function, initializing the object, and, if an exception occurs
    during construction, cleaning up.  The arguments are as for
-   build_raw_new_expr.
-   We take an additional NELTS_FOR_TYPE for the case we want NELTS to
-   have nodes that shouldn't be on a type. */
+   build_raw_new_expr.  */
 
 static tree
-build_new_1 (tree placement, tree type, tree nelts, tree nelts_for_type,
-	     tree init, bool globally_qualified_p, tsubst_flags_t complain)
+build_new_1 (tree placement, tree type, tree nelts, tree init,
+	     bool globally_qualified_p, tsubst_flags_t complain)
 {
   tree size, rval;
   /* True iff this is a call to "operator new[]" instead of just
@@ -1880,7 +1878,7 @@ build_new_1 (tree placement, tree type, 
 	     necessary in order for the <INIT_EXPR <*foo> <CONSTRUCTOR
 	     ...>> to be valid.  */
 	  TYPE_SIZE_UNIT (full_type) = size;
-	  n = convert (bitsizetype, nelts_for_type);
+	  n = convert (bitsizetype, nelts);
 	  bitsize = size_binop (MULT_EXPR, TYPE_SIZE (elt_type), n);
 	  TYPE_SIZE (full_type) = bitsize;
 	}
@@ -2326,7 +2324,6 @@ build_new (tree placement, tree type, tr
   tree orig_placement;
   tree orig_nelts;
   tree orig_init;
-  tree nelts_for_type = NULL;
 
   if (placement == error_mark_node || type == error_mark_node
       || init == error_mark_node)
@@ -2369,10 +2366,7 @@ build_new (tree placement, tree type, tr
           else
             return error_mark_node;
         }
-      /* Avoid having SAVE_EXPR on a type. */
-      nelts_for_type = cp_convert (sizetype, nelts);
-      nelts = cp_save_expr (nelts_for_type);
-
+      nelts = cp_save_expr (cp_convert (sizetype, nelts));
     }
 
   /* ``A reference cannot be created by the new operator.  A reference
@@ -2400,8 +2394,7 @@ build_new (tree placement, tree type, tr
   if (!complete_type_or_else (type, NULL_TREE))
     return error_mark_node;
 
-  rval = build_new_1 (placement, type, nelts, nelts_for_type, init,
-		      use_global_new, complain);
+  rval = build_new_1 (placement, type, nelts, init, use_global_new, complain);
   if (rval == error_mark_node)
     return error_mark_node;
 



More information about the Gcc-patches mailing list