This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, wrong-code, 4.2/4.3/4.4 regression] Patch for PR38615
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>, Andrew Pinski <pinskia at gmail dot com>, Richard Guenther <richard dot guenther at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 Jan 2009 09:54:02 -0800 (PST)
- Subject: Re: [patch, wrong-code, 4.2/4.3/4.4 regression] Patch for PR38615
Here is my new patch using -fmerge-all-constants and updating the
documentation for that option with Joseph's suggested changes.
I am assuming that in addition to doing the optimization when
-fmerge-all-constants is set we still want to do the optimization if
TREE_ADDRESSABLE is false since it shouldn't be a problem in that case.
Is that true?
Currently retesting.
Steve Ellcey
sje@cup.hp.com
2009-01-21 Steve Ellcey <sje@cup.hp.com>
PR middle-end/38615
* gimplify.c (gimplify_init_constructor): Fix promotion of const
variables to static.
* doc/invoke.texi (-fmerge-all-constants): Update description.
Index: gimplify.c
===================================================================
--- gimplify.c (revision 143537)
+++ gimplify.c (working copy)
@@ -3526,7 +3526,8 @@ gimplify_init_constructor (tree *expr_p,
if (valid_const_initializer
&& num_nonzero_elements > 1
&& TREE_READONLY (object)
- && TREE_CODE (object) == VAR_DECL)
+ && TREE_CODE (object) == VAR_DECL
+ && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object)))
{
if (notify_temp_creation)
return GS_ERROR;
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 143537)
+++ doc/invoke.texi (working copy)
@@ -5468,8 +5468,9 @@ Attempt to merge identical constants and
This option implies @option{-fmerge-constants}. In addition to
@option{-fmerge-constants} this considers e.g.@: even constant initialized
arrays or initialized constant variables with integral or floating point
-types. Languages like C or C++ require each non-automatic variable to
-have distinct location, so using this option will result in non-conforming
+types. Languages like C or C++ require each variable, including multiple
+instances of the same variable in recursive calls, to have distinct locations,
+so using this option will result in non-conforming
behavior.
@item -fmodulo-sched
2009-01-21 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;
+}