re PR c++/36688 (Incorrect struct assignments with nested const initializers)
authorJakub Jelinek <jakub@redhat.com>
Tue, 12 Aug 2008 08:07:57 +0000 (10:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 12 Aug 2008 08:07:57 +0000 (10:07 +0200)
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.

From-SVN: r139004

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/const6.C [new file with mode: 0644]

index dfa628e..be9020e 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2008-08-12  Ira Rosen  <irar@il.ibm.com>
 
        * tree-vectorizer.c: Depend on langhooks.h.
index f22111d..753aa59 100644 (file)
@@ -3913,7 +3913,7 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_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)
          {
index 55f1706..d6f2811 100644 (file)
@@ -1,3 +1,8 @@
+2008-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/36688
+       * g++.dg/init/const6.C: New test.
+
 2008-08-12  Ira Rosen  <irar@il.ibm.com>
 
        * gcc.dg/vect/vect-multitypes-12.c: New.
diff --git a/gcc/testsuite/g++.dg/init/const6.C b/gcc/testsuite/g++.dg/init/const6.C
new file mode 100644 (file)
index 0000000..f341969
--- /dev/null
@@ -0,0 +1,27 @@
+// PR c++/36688
+// { dg-do compile }
+// { 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 ();
+}