Commit 2234a9cb by Patrick Palka

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
parent 3f6a2f9e
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> 2015-04-17 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/64950 PR tree-optimization/64950
......
...@@ -3994,6 +3994,9 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, ...@@ -3994,6 +3994,9 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
pre_p, post_p, &preeval_data); pre_p, post_p, &preeval_data);
} }
bool ctor_has_side_effects_p
= TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1));
if (cleared) if (cleared)
{ {
/* Zap the CONSTRUCTOR element list, which simplifies this case. /* 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, ...@@ -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 /* If we have not block cleared the object, or if there are nonzero
elements in the constructor, add assignments to the individual elements in the constructor, or if the constructor has side effects,
scalar fields of the object. */ add assignments to the individual scalar fields of the object. */
if (!cleared || num_nonzero_elements > 0) if (!cleared
|| num_nonzero_elements > 0
|| ctor_has_side_effects_p)
gimplify_init_ctor_eval (object, elts, pre_p, cleared); gimplify_init_ctor_eval (object, elts, pre_p, cleared);
*expr_p = NULL_TREE; *expr_p = NULL_TREE;
......
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> 2015-04-17 Tom de Vries <tom@codesourcery.com>
Michael Matz <matz@suse.de> Michael Matz <matz@suse.de>
......
// { 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 ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment