+2016-05-20 Jakub Jelinek <jakub@redhat.com>
+
+ 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 <marc.glisse@inria.fr>
PR tree-optimization/71079
}
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)
{
2016-05-20 Jakub Jelinek <jakub@redhat.com>
+ 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
--- /dev/null
+// PR c++/71210
+// { dg-do compile }
+// { dg-options "-O2" }
+
+#include <typeinfo>
+
+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 (); }
--- /dev/null
+// 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);
+}