diff options
author | Jason Merrill <jason@redhat.com> | 2012-05-30 18:07:23 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-05-30 18:07:23 -0400 |
commit | 66edf32a6fd51d8ad5815e5d995421f037dadadc (patch) | |
tree | d1c3613ebc8501879f700da9fe979baaf912a1dd /gcc | |
parent | 989e6706f1077a333b515ffd1abc8ab73a016562 (diff) | |
download | gcc-66edf32a6fd51d8ad5815e5d995421f037dadadc.zip gcc-66edf32a6fd51d8ad5815e5d995421f037dadadc.tar.gz gcc-66edf32a6fd51d8ad5815e5d995421f037dadadc.tar.bz2 |
re PR c++/53356 (ICE in verify_gimple_stmt, at tree-cfg.c:4258)
PR c++/53356
* tree.c (stabilize_init): Handle stabilizing a TARGET_EXPR
representing a bitwise copy of a glvalue.
From-SVN: r188029
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/tree.c | 45 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/new34.C | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tree-ssa/stabilize1.C | 14 |
5 files changed, 63 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 89cbc90..2dcdb77 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2012-05-30 Jason Merrill <jason@redhat.com> + PR c++/53356 + * tree.c (stabilize_init): Handle stabilizing a TARGET_EXPR + representing a bitwise copy of a glvalue. + * tree.c (stabilize_expr): Tweak logic. PR c++/53356 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 4e7056f..2b541cd 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3389,7 +3389,7 @@ stabilize_aggr_init (tree call, tree *initp) takes care not to introduce additional temporaries. Returns TRUE iff the expression was successfully pre-evaluated, - i.e., if INIT is now side-effect free, except for, possible, a + i.e., if INIT is now side-effect free, except for, possibly, a single call to a constructor. */ bool @@ -3402,21 +3402,37 @@ stabilize_init (tree init, tree *initp) if (t == error_mark_node || processing_template_decl) return true; - if (TREE_CODE (t) == INIT_EXPR - && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR - && TREE_CODE (TREE_OPERAND (t, 1)) != CONSTRUCTOR - && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR) - { - TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp); - return true; - } - if (TREE_CODE (t) == INIT_EXPR) t = TREE_OPERAND (t, 1); if (TREE_CODE (t) == TARGET_EXPR) t = TARGET_EXPR_INITIAL (t); - if (TREE_CODE (t) == COMPOUND_EXPR) - t = expr_last (t); + + /* If the RHS can be stabilized without breaking copy elision, stabilize + it. We specifically don't stabilize class prvalues here because that + would mean an extra copy, but they might be stabilized below. */ + if (TREE_CODE (init) == INIT_EXPR + && TREE_CODE (t) != CONSTRUCTOR + && TREE_CODE (t) != AGGR_INIT_EXPR + && (SCALAR_TYPE_P (TREE_TYPE (t)) + || lvalue_or_rvalue_with_address_p (t))) + { + TREE_OPERAND (init, 1) = stabilize_expr (t, initp); + return true; + } + + if (TREE_CODE (t) == COMPOUND_EXPR + && TREE_CODE (init) == INIT_EXPR) + { + tree last = expr_last (t); + /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */ + if (!TREE_SIDE_EFFECTS (last)) + { + *initp = t; + TREE_OPERAND (init, 1) = last; + return true; + } + } + if (TREE_CODE (t) == CONSTRUCTOR) { /* Aggregate initialization: stabilize each of the field @@ -3439,11 +3455,6 @@ stabilize_init (tree init, tree *initp) return good; } - /* If the initializer is a COND_EXPR, we can't preevaluate - anything. */ - if (TREE_CODE (t) == COND_EXPR) - return false; - if (TREE_CODE (t) == CALL_EXPR) { stabilize_call (t, initp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae6bdaf..44f71cb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2012-05-30 Jason Merrill <jason@redhat.com> + + PR c++/53356 + * g++.dg/init/new34.C: New. + * g++.dg/tree-ssa/stabilize1.C: New. + 2012-05-30 Jakub Jelinek <jakub@redhat.com> PR c++/53356 diff --git a/gcc/testsuite/g++.dg/init/new34.C b/gcc/testsuite/g++.dg/init/new34.C new file mode 100644 index 0000000..9e67eb34 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new34.C @@ -0,0 +1,11 @@ +// PR c++/53356 + +struct A { A(); ~A(); }; + +struct B { + operator const A () const; +}; + +A* cause_ICE() { + return new A((A(),A())); +} diff --git a/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C b/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C new file mode 100644 index 0000000..2fe723c --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/stabilize1.C @@ -0,0 +1,14 @@ +// PR c++/53356 +// { dg-options "-fdump-tree-gimple" } +// { dg-final { scan-tree-dump-not "= 0" "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } } + +class A {}; + +struct B { + operator const A &() const; +}; + +A* cause_ICE() { + return new A(B()); +} |