diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b283f28fb38..d91b75e9a2d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-01-31 Richard Guenther + + PR middle-end/42898 + * gimplify.c (gimplify_init_constructor): For volatile LHS + initialize a temporary. + 2010-01-31 Matthias Klose * configure.ac: Fix __stack_chk_fail check for cross builds configured diff --git a/gcc/gimplify.c b/gcc/gimplify.c index ccae4d89a72..fac3fdaa223 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3745,6 +3745,21 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } } + /* If the target is volatile and we have non-zero elements + initialize the target from a temporary. */ + if (TREE_THIS_VOLATILE (object) + && !TREE_ADDRESSABLE (type) + && num_nonzero_elements > 0) + { + tree temp = create_tmp_var (TYPE_MAIN_VARIANT (type), NULL); + TREE_OPERAND (*expr_p, 0) = temp; + *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p), + *expr_p, + build2 (MODIFY_EXPR, void_type_node, + object, temp)); + return GS_OK; + } + if (notify_temp_creation) return GS_OK; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8257646e9a5..23730795d5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-01-31 Richard Guenther + + PR middle-end/42898 + * gcc.dg/torture/pr42898.c: New testcase. + 2010-01-31 Paul Thomas PR fortran/38324 diff --git a/gcc/testsuite/gcc.dg/torture/pr42898.c b/gcc/testsuite/gcc.dg/torture/pr42898.c new file mode 100644 index 00000000000..df8b46a6295 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr42898.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-optimized" } */ + +struct hardware { + int parm1:8; + int :4; + int parm2:4; + int parm3:15; + int parm4:1; +}; + +void f1(volatile struct hardware *ptr) +{ + *ptr=(struct hardware) { + .parm1=42, + .parm2=13, + .parm3=11850, + .parm4=1, + }; +} + +/* { dg-final { scan-tree-dump-times "\\*ptr" 1 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */