This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix gimplify_modify_expr_rhs optimization with const VAR_DECL initializers (PR c++/36688)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 12 Aug 2008 04:39:33 -0400
- Subject: [PATCH] Fix gimplify_modify_expr_rhs optimization with const VAR_DECL initializers (PR c++/36688)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
C++ const qualified static vars that have parts of initialization done
at compile time and part in static initialization have the type const
qualified, but the VAR_DECL is not (as it is written by static
initialization). In these cases gimplify_modify_expr_rhs must not
optimize initialization to DECL_INITIAL of the VAR_DECL, as that
initializer is incomplete. I've bootstrapped/regtested this
on x86_64-linux, as well as bootstrapped/regtested with a version that
asserted TYPE_READONLY (TREE_TYPE (*from_p)) is the same as
TREE_READONLY (*from_p) (the latter only ICEd on the newly added testcase,
not any other testcase during make check nor during bootstrap;
just wanted to see how much code it affects).
Committed to trunk/4.3.
2008-08-12 Jakub Jelinek <jakub@redhat.com>
PR c++/36688
* gimplify.c (gimplify_modify_expr_rhs): Test TREE_READONLY
on the VAR_DECL instead of TYPE_READONLY on its type.
* g++.dg/init/const6.C: New test.
--- gcc/gimplify.c.jj 2008-08-11 10:54:27.000000000 +0200
+++ gcc/gimplify.c 2008-08-12 00:52:45.000000000 +0200
@@ -3913,7 +3913,7 @@ gimplify_modify_expr_rhs (tree *expr_p,
/* If we're assigning from a constant constructor, move the
constructor expression to the RHS of the MODIFY_EXPR. */
if (DECL_INITIAL (*from_p)
- && TYPE_READONLY (TREE_TYPE (*from_p))
+ && TREE_READONLY (*from_p)
&& !TREE_THIS_VOLATILE (*from_p)
&& TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR)
{
--- gcc/testsuite/g++.dg/init/const6.C.jj 2008-08-12 00:53:50.000000000 +0200
+++ gcc/testsuite/g++.dg/init/const6.C 2008-08-12 00:54:17.000000000 +0200
@@ -0,0 +1,27 @@
+// PR c++/36688
+// { dg-do run }
+// { dg-options "-O2" }
+
+struct S
+{
+ long long a;
+ long long b;
+ long long c;
+};
+
+struct T
+{
+ S g;
+ long long h[12];
+};
+
+static const S s = { 1, 2, 3 };
+static const T t = { s, 0 };
+
+int
+main ()
+{
+ T x = t;
+ if (__builtin_memcmp (&x, &t, sizeof (T)))
+ __builtin_abort ();
+}
Jakub