From: Jakub Jelinek Date: Fri, 20 May 2016 11:58:49 +0000 (+0200) Subject: re PR c++/71210 (internal compiler error: in assign_temp, at function.c:961) X-Git-Tag: upstream/12.2.0~46952 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1895484016aa288d135e1e475eb3afaa04a4e7b6;p=platform%2Fupstream%2Fgcc.git re PR c++/71210 (internal compiler error: in assign_temp, at function.c:961) PR c++/71210 * gimple-fold.c (gimple_fold_call): Do not remove lhs of noreturn calls if the LHS is variable length or has addressable type. If targets[0]->decl is a noreturn call with void return type and zero arguments, adjust fntype and remove lhs in that case. * g++.dg/opt/pr71210-1.C: New test. * g++.dg/opt/pr71210-2.C: New test. From-SVN: r236506 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f874a6c..403c01f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-05-20 Jakub Jelinek + + PR c++/71210 + * gimple-fold.c (gimple_fold_call): Do not remove lhs of noreturn + calls if the LHS is variable length or has addressable type. + If targets[0]->decl is a noreturn call with void return type and + zero arguments, adjust fntype and remove lhs in that case. + 2016-05-20 Marc Glisse PR tree-optimization/71079 diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index d3968e9..858f484 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3039,10 +3039,25 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) } if (targets.length () == 1) { - gimple_call_set_fndecl (stmt, targets[0]->decl); + tree fndecl = targets[0]->decl; + gimple_call_set_fndecl (stmt, fndecl); changed = true; + /* If changing the call to __cxa_pure_virtual + or similar noreturn function, adjust gimple_call_fntype + too. */ + if ((gimple_call_flags (stmt) & ECF_NORETURN) + && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))) + && TYPE_ARG_TYPES (TREE_TYPE (fndecl)) + && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) + == void_type_node)) + gimple_call_set_fntype (stmt, TREE_TYPE (fndecl)); /* If the call becomes noreturn, remove the lhs. */ - if (lhs && (gimple_call_flags (stmt) & ECF_NORETURN)) + if (lhs + && (gimple_call_flags (stmt) & ECF_NORETURN) + && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (stmt))) + || ((TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) + == INTEGER_CST) + && !TREE_ADDRESSABLE (TREE_TYPE (lhs))))) { if (TREE_CODE (lhs) == SSA_NAME) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 94080ab..fe4727a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2016-05-20 Jakub Jelinek + PR c++/71210 + * g++.dg/opt/pr71210-1.C: New test. + * g++.dg/opt/pr71210-2.C: New test. + PR tree-optimization/29756 gcc.dg/tree-ssa/vector-6.c: Add -Wno-psabi -w to dg-options. Add -msse2 for x86 and -maltivec for powerpc. Use scan-tree-dump-times diff --git a/gcc/testsuite/g++.dg/opt/pr71210-1.C b/gcc/testsuite/g++.dg/opt/pr71210-1.C new file mode 100644 index 0000000..03b1fb5 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr71210-1.C @@ -0,0 +1,14 @@ +// PR c++/71210 +// { dg-do compile } +// { dg-options "-O2" } + +#include + +void f1 (const std::type_info&) __attribute__((noreturn)); +struct S1 { ~S1 (); }; +struct S2 +{ + virtual S1 f2 () const { f1 (typeid (*this)); } + S1 f3 () const { return f2 (); } +}; +void f4 () { S2 a; a.f3 (); } diff --git a/gcc/testsuite/g++.dg/opt/pr71210-2.C b/gcc/testsuite/g++.dg/opt/pr71210-2.C new file mode 100644 index 0000000..02a31bd --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr71210-2.C @@ -0,0 +1,23 @@ +// PR c++/71210 +// { dg-do compile } +// { dg-options "-O2" } + +struct C { int a; int b; C (); ~C (); }; + +namespace +{ + struct A + { + A () {} + virtual C bar (int) = 0; + C baz (int x) { return bar (x); } + }; +} + +A *a; + +void +foo () +{ + C c = a->baz (0); +}