diff options
author | Patrick Palka <ppalka@gcc.gnu.org> | 2015-04-17 12:14:24 +0000 |
---|---|---|
committer | Patrick Palka <ppalka@gcc.gnu.org> | 2015-04-17 12:14:24 +0000 |
commit | 2234a9cb75c9f2ba6d6b944a93c673e5b3fc004a (patch) | |
tree | e673e0b8a136f5b01ca1c70882bc13acd7a0cfd5 | |
parent | 3f6a2f9e08e49561d682d334d383ec1be9d4dc92 (diff) | |
download | gcc-2234a9cb75c9f2ba6d6b944a93c673e5b3fc004a.zip gcc-2234a9cb75c9f2ba6d6b944a93c673e5b3fc004a.tar.gz gcc-2234a9cb75c9f2ba6d6b944a93c673e5b3fc004a.tar.bz2 |
re PR c++/64527 (Constructor for empty struct not called in some situations)
Fix PR c++/64527
gcc/
PR c++/64527
* gimplify.c (gimplify_init_constructor): Always emit a
side-effecting constructor.
gcc/testsuite/
PR c++/64527
* g++.dg/init/pr64527.C: New test.
From-SVN: r222176
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/gimplify.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/pr64527.C | 21 |
4 files changed, 40 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8929d06..bd25dd7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-04-17 Patrick Palka <ppalka@gcc.gnu.org> + + PR c++/64527 + * gimplify.c (gimplify_init_constructor): Always emit a + side-effecting constructor. + 2015-04-17 Tom de Vries <tom@codesourcery.com> PR tree-optimization/64950 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 0394543..c701ef3 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3994,6 +3994,9 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, pre_p, post_p, &preeval_data); } + bool ctor_has_side_effects_p + = TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1)); + if (cleared) { /* Zap the CONSTRUCTOR element list, which simplifies this case. @@ -4006,9 +4009,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } /* If we have not block cleared the object, or if there are nonzero - elements in the constructor, add assignments to the individual - scalar fields of the object. */ - if (!cleared || num_nonzero_elements > 0) + elements in the constructor, or if the constructor has side effects, + add assignments to the individual scalar fields of the object. */ + if (!cleared + || num_nonzero_elements > 0 + || ctor_has_side_effects_p) gimplify_init_ctor_eval (object, elts, pre_p, cleared); *expr_p = NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b9b576..1f9f1d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-04-17 Patrick Palka <ppalka@gcc.gnu.org> + + PR c++/64527 + * g++.dg/init/pr64527.C: New test. + 2015-04-17 Tom de Vries <tom@codesourcery.com> Michael Matz <matz@suse.de> diff --git a/gcc/testsuite/g++.dg/init/pr64527.C b/gcc/testsuite/g++.dg/init/pr64527.C new file mode 100644 index 0000000..36b8214 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr64527.C @@ -0,0 +1,21 @@ +// { dg-do run { target c++11 } } + +static int g; + +struct A { + A() { g = 1; } +}; + +struct accessor { + A a; + int x; +}; + +int +main (void) +{ + (void) accessor{}; + + if (g != 1) + __builtin_abort (); +} |