aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2014-01-09 21:09:33 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2014-01-09 21:09:33 +0100
commita70e9985fdc020e89eace3d72108606c47150fc5 (patch)
tree6ca99a99212dfd53b8fe2ea60d34b8cdff1d5e2d /gcc
parent94c13a09115ce6b419c5ed809630e746ba1ae134 (diff)
downloadgcc-a70e9985fdc020e89eace3d72108606c47150fc5.zip
gcc-a70e9985fdc020e89eace3d72108606c47150fc5.tar.gz
gcc-a70e9985fdc020e89eace3d72108606c47150fc5.tar.bz2
re PR tree-optimization/59622 (internal compiler error: verify_gimple failed)
PR tree-optimization/59622 * gimple-fold.c (gimple_fold_call): Fix a typo in message. For __builtin_unreachable replace the OBJ_TYPE_REF call with a call to __builtin_unreachable and add if needed a setter of the lhs SSA_NAME. Don't devirtualize for inplace at all. For targets.length () == 1, if the call is noreturn and cfun isn't in SSA form yet, clear lhs. * g++.dg/opt/pr59622-2.C: New test. * g++.dg/opt/pr59622-3.C: New test. * g++.dg/opt/pr59622-4.C: New test. * g++.dg/opt/pr59622-5.C: New test. From-SVN: r206492
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/gimple-fold.c29
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/opt/pr59622-2.C21
-rw-r--r--gcc/testsuite/g++.dg/opt/pr59622-3.C21
-rw-r--r--gcc/testsuite/g++.dg/opt/pr59622-4.C23
-rw-r--r--gcc/testsuite/g++.dg/opt/pr59622-5.C26
7 files changed, 132 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f657946..7d000f2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2014-01-09 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/59622
+ * gimple-fold.c (gimple_fold_call): Fix a typo in message. For
+ __builtin_unreachable replace the OBJ_TYPE_REF call with a call to
+ __builtin_unreachable and add if needed a setter of the lhs SSA_NAME.
+ Don't devirtualize for inplace at all. For targets.length () == 1,
+ if the call is noreturn and cfun isn't in SSA form yet, clear lhs.
+
2014-01-09 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/i386.md (cpu): Remove the unused btver1.
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 91fc297..b2b3876 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1167,7 +1167,7 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
(OBJ_TYPE_REF_EXPR (callee)))))
{
fprintf (dump_file,
- "Type inheritnace inconsistent devirtualization of ");
+ "Type inheritance inconsistent devirtualization of ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
fprintf (dump_file, " to ");
print_generic_expr (dump_file, callee, TDF_SLIM);
@@ -1177,24 +1177,45 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
gimple_call_set_fn (stmt, OBJ_TYPE_REF_EXPR (callee));
changed = true;
}
- else if (flag_devirtualize && virtual_method_call_p (callee))
+ else if (flag_devirtualize && !inplace && virtual_method_call_p (callee))
{
bool final;
vec <cgraph_node *>targets
= possible_polymorphic_call_targets (callee, &final);
if (final && targets.length () <= 1)
{
+ tree lhs = gimple_call_lhs (stmt);
if (targets.length () == 1)
{
gimple_call_set_fndecl (stmt, targets[0]->decl);
changed = true;
+ /* If the call becomes noreturn, remove the lhs. */
+ if (lhs && (gimple_call_flags (stmt) & ECF_NORETURN))
+ {
+ if (TREE_CODE (lhs) == SSA_NAME)
+ {
+ tree var = create_tmp_var (TREE_TYPE (lhs), NULL);
+ tree def = get_or_create_ssa_default_def (cfun, var);
+ gimple new_stmt = gimple_build_assign (lhs, def);
+ gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
+ }
+ gimple_call_set_lhs (stmt, NULL_TREE);
+ }
}
- else if (!inplace)
+ else
{
tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
gimple new_stmt = gimple_build_call (fndecl, 0);
gimple_set_location (new_stmt, gimple_location (stmt));
- gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
+ if (lhs && TREE_CODE (lhs) == SSA_NAME)
+ {
+ tree var = create_tmp_var (TREE_TYPE (lhs), NULL);
+ tree def = get_or_create_ssa_default_def (cfun, var);
+ gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
+ update_call_from_tree (gsi, def);
+ }
+ else
+ gsi_replace (gsi, new_stmt, true);
return true;
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index acb1637..d6a7a01 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,4 +1,10 @@
-2014-10-09 Jakub Jelinek <jakub@redhat.com>
+2014-01-09 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/59622
+ * g++.dg/opt/pr59622-2.C: New test.
+ * g++.dg/opt/pr59622-3.C: New test.
+ * g++.dg/opt/pr59622-4.C: New test.
+ * g++.dg/opt/pr59622-5.C: New test.
PR sanitizer/59136
* c-c++-common/asan/strip-path-prefix-1.c: Allow also the
diff --git a/gcc/testsuite/g++.dg/opt/pr59622-2.C b/gcc/testsuite/g++.dg/opt/pr59622-2.C
new file mode 100644
index 0000000..8096eeb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr59622-2.C
@@ -0,0 +1,21 @@
+// PR tree-optimization/59622
+// { dg-do compile }
+// { dg-options "-O2" }
+
+namespace
+{
+ struct A
+ {
+ A () {}
+ virtual A *bar (int) = 0;
+ A *baz (int x) { return bar (x); }
+ };
+}
+
+A *a;
+
+void
+foo ()
+{
+ a->baz (0);
+}
diff --git a/gcc/testsuite/g++.dg/opt/pr59622-3.C b/gcc/testsuite/g++.dg/opt/pr59622-3.C
new file mode 100644
index 0000000..0af8605
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr59622-3.C
@@ -0,0 +1,21 @@
+// PR tree-optimization/59622
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct C { int a; int b; };
+
+namespace
+{
+ struct A
+ {
+ virtual C foo ();
+ C bar () { return foo (); }
+ };
+}
+
+C
+baz ()
+{
+ A a;
+ return a.bar ();
+}
diff --git a/gcc/testsuite/g++.dg/opt/pr59622-4.C b/gcc/testsuite/g++.dg/opt/pr59622-4.C
new file mode 100644
index 0000000..f72af16
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr59622-4.C
@@ -0,0 +1,23 @@
+// PR tree-optimization/59622
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct C { int a; int b; };
+
+namespace
+{
+ struct A
+ {
+ A () {}
+ virtual C bar (int) = 0;
+ C baz (int x) { return bar (x); }
+ };
+}
+
+A *a;
+
+C
+foo ()
+{
+ return a->baz (0);
+}
diff --git a/gcc/testsuite/g++.dg/opt/pr59622-5.C b/gcc/testsuite/g++.dg/opt/pr59622-5.C
new file mode 100644
index 0000000..bcb2591
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr59622-5.C
@@ -0,0 +1,26 @@
+// PR tree-optimization/59622
+// { dg-do compile }
+// { dg-options "-O2" }
+
+namespace
+{
+ struct A
+ {
+ A () {}
+ virtual A *bar (int);
+ A *baz (int x) { return bar (x); }
+ };
+
+ __attribute__((noreturn)) A *A::bar (int)
+ {
+ __builtin_exit (0);
+ }
+}
+
+A *a;
+
+void
+foo ()
+{
+ a->baz (0);
+}