From: Eric Botcazou Date: Sun, 31 Jan 2010 21:08:15 +0000 (+0000) Subject: re PR middle-end/42898 (volatile structures and compound literal initializers) X-Git-Tag: releases/gcc-4.3.5~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e023c7b0a0a101ea88a21cdd2d249a17adc8dcd1;p=thirdparty%2Fgcc.git re PR middle-end/42898 (volatile structures and compound literal initializers) 2010-01-31 Eric Botcazou PR middle-end/42898 Backport from mainline: 2009-04-23 Eric Botcazou * gimplify.c (gimplify_modify_expr_rhs) : Do not do a direct assignment from the constructor either if the target is volatile. From-SVN: r156416 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e05c1fd7c699..67438610a930 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2010-01-31 Eric Botcazou + + PR middle-end/42898 + Backport from mainline: + 2009-04-23 Eric Botcazou + + * gimplify.c (gimplify_modify_expr_rhs) : Do not do a direct + assignment from the constructor either if the target is volatile. + 2010-01-31 Richard Guenther PR middle-end/42898 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 71af972b2659..897c185c1437 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3566,11 +3566,14 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, tree *pre_p, switch (TREE_CODE (*from_p)) { case VAR_DECL: - /* If we're assigning from a constant constructor, move the - constructor expression to the RHS of the MODIFY_EXPR. */ + /* If we're assigning from a read-only variable initialized with + a constructor, do the direct assignment from the constructor, + but only if neither source nor target are volatile since this + latter assignment might end up being done on a per-field basis. */ if (DECL_INITIAL (*from_p) && TREE_READONLY (*from_p) && !TREE_THIS_VOLATILE (*from_p) + && !TREE_THIS_VOLATILE (*to_p) && TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR) { tree old_from = *from_p; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 000461bc853d..ca235f90799f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-01-31 Eric Botcazou + + PR middle-end/42898 + * gcc.dg/torture/pr42898-2.c: New test. + 2010-01-31 Richard Guenther * gcc.dg/torture/pr42898.c: Skip -O0. diff --git a/gcc/testsuite/gcc.dg/torture/pr42898-2.c b/gcc/testsuite/gcc.dg/torture/pr42898-2.c new file mode 100644 index 000000000000..32c94273b135 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr42898-2.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ +/* { dg-options "-fdump-tree-optimized" } */ + +struct hardware { + int parm1:8; + int :4; + int parm2:4; + int parm3:15; + int parm4:1; +}; + +const struct hardware h = { + .parm1=42, + .parm2=13, + .parm3=11850, + .parm4=1, +}; + +void f1(volatile struct hardware *ptr) +{ + *ptr = h; +} + +/* { dg-final { scan-tree-dump-times "\\*ptr" 1 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */