This removes the ability to follow statements that can throw internally.
This was suggested in bug report as a way to solve the issue here.
The overhead is not that high since without non-call exceptions turned
on, there is an early exit for non-calls.
PR tree-optimization/119903
gcc/ChangeLog:
* gimple-match-head.cc (get_def): Reject statements that can throw
internally.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/pr119903-1.C: New test.
Signed-off-by: Andrew Pinski <[email protected]>
---
gcc/gimple-match-head.cc | 5 ++++-
gcc/testsuite/g++.dg/tree-ssa/pr119903-1.C | 24 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr119903-1.C
diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
index 6b3c5febbea..62ff8e57fbb 100644
--- a/gcc/gimple-match-head.cc
+++ b/gcc/gimple-match-head.cc
@@ -63,7 +63,10 @@ get_def (tree (*valueize)(tree), tree name)
{
if (valueize && ! valueize (name))
return NULL;
- return SSA_NAME_DEF_STMT (name);
+ gimple *t = SSA_NAME_DEF_STMT (name);
+ if (stmt_can_throw_internal (cfun, t))
+ return nullptr;
+ return t;
}
/* Routine to determine if the types T1 and T2 are effectively
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr119903-1.C
b/gcc/testsuite/g++.dg/tree-ssa/pr119903-1.C
new file mode 100644
index 00000000000..605f989a2eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr119903-1.C
@@ -0,0 +1,24 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fnon-call-exceptions -ftrapping-math
-fdump-tree-optimized-eh" }
+
+// PR tree-optimization/119903
+// match and simplify would cause the internal throwable fp comparison
+// to become only external throwable and lose the landing pad.
+
+int f() noexcept;
+int g() noexcept;
+
+int m(double a)
+{
+ try {
+ if (a < 1.0)
+ return f();
+ return g();
+ }catch(...)
+ {
+ return -1;
+ }
+}
+
+// Make sure There is a landing pad for the non-call exception from the
comparison.
+// { dg-final { scan-tree-dump "LP " "optimized" } }
--
2.43.0