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]

[patch, wrong-code, 4.2/4.3/4.4 regression] Patch for PR38615


PR middle-end/38615 is a wrong-code bug on the list of 4.4 regressions.

Promoting a initalitialized const auto variable to static appears to be
an invalid optimization so this patch removes it.  This change could
have a performance impact but I made no attempt to measure it since the
optimization is invalid and just shouldn't be done.

Tested on IA64 HP-UX and Linux.

OK for checkin?


2009-01-20  Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/38615
	* gimplify.c (gimplify_init_constructor): Do not promote const
	variable to static.


Index: gimplify.c
===================================================================
--- gimplify.c	(revision 143507)
+++ gimplify.c	(working copy)
@@ -3521,34 +3521,6 @@ gimplify_init_constructor (tree *expr_p,
 	  = categorize_ctor_elements (ctor, &num_nonzero_elements,
 				      &num_ctor_elements, &cleared);
 
-	/* If a const aggregate variable is being initialized, then it
-	   should never be a lose to promote the variable to be static.  */
-	if (valid_const_initializer
-	    && num_nonzero_elements > 1
-	    && TREE_READONLY (object)
-	    && TREE_CODE (object) == VAR_DECL)
-	  {
-	    if (notify_temp_creation)
-	      return GS_ERROR;
-	    DECL_INITIAL (object) = ctor;
-	    TREE_STATIC (object) = 1;
-	    if (!DECL_NAME (object))
-	      DECL_NAME (object) = create_tmp_var_name ("C");
-	    walk_tree (&DECL_INITIAL (object), force_labels_r, NULL, NULL);
-
-	    /* ??? C++ doesn't automatically append a .<number> to the
-	       assembler name, and even when it does, it looks a FE private
-	       data structures to figure out what that number should be,
-	       which are not set for this variable.  I suppose this is
-	       important for local statics for inline functions, which aren't
-	       "local" in the object file sense.  So in order to get a unique
-	       TU-local symbol, we must invoke the lhd version now.  */
-	    lhd_set_decl_assembler_name (object);
-
-	    *expr_p = NULL_TREE;
-	    break;
-	  }
-
 	/* If there are "lots" of initialized elements, even discounting
 	   those that are not address constants (and thus *must* be
 	   computed at runtime), then partition the constructor into





2009-01-20  Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/38615
	* gcc.dg/pr38615.c: New test.


Index: gcc.dg/pr38615.c
===================================================================
--- gcc.dg/pr38615.c	(revision 0)
+++ gcc.dg/pr38615.c	(revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+int t;
+extern void abort (void);
+
+int f(int t, const int *a)
+{
+ const int b[] = { 1, 2, 3};
+ if (!t)
+   return f(1, b);
+ return b == a;
+}
+
+int main(void)
+{
+ if (f(0, 0))
+   abort ();
+ return 0;
+}


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