From: Jakub Jelinek Date: Tue, 12 Aug 2008 08:07:57 +0000 (+0200) Subject: re PR c++/36688 (Incorrect struct assignments with nested const initializers) X-Git-Tag: releases/gcc-4.4.0~3187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d7231a35cc789bc7e42835e74a3f3131bb57518;p=thirdparty%2Fgcc.git re PR c++/36688 (Incorrect struct assignments with nested const initializers) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dfa628ef3026..be9020ef9c8d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-08-12 Jakub Jelinek + + 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 * tree-vectorizer.c: Depend on langhooks.h. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index f22111d4cd7f..753aa591e405 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 55f170602d6a..d6f281122e3e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-08-12 Jakub Jelinek + + PR c++/36688 + * g++.dg/init/const6.C: New test. + 2008-08-12 Ira Rosen * 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 index 000000000000..f34196931a18 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/const6.C @@ -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 (); +}