]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/108691 - remove trigger-happy assert
authorRichard Biener <rguenther@suse.de>
Tue, 21 Feb 2023 12:02:31 +0000 (13:02 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 21 Feb 2023 13:02:58 +0000 (14:02 +0100)
The following gets rid of the idea that we should prevent setjmp
like calls from popping up in uncontrolled way in the IL for now.
The solution is probably to handle it similar as noreturn has
the ctrl-altering flag on stmts, but use another flag, for example
ctrl-receiving which would also make sure the stmt is first.

PR tree-optimization/108691
* tree-ssa-dce.cc (eliminate_unnecessary_stmts): Remove
assert about calls_setjmp not becoming true when it was false.

* gcc.dg/pr108691.c: New testcase.

gcc/testsuite/gcc.dg/pr108691.c [new file with mode: 0644]
gcc/tree-ssa-dce.cc

diff --git a/gcc/testsuite/gcc.dg/pr108691.c b/gcc/testsuite/gcc.dg/pr108691.c
new file mode 100644 (file)
index 0000000..e412df1
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern int __attribute__((returns_twice)) setjmp(void*);
+
+void bbb(void) {
+  int (*fnptr)(void*) = setjmp;
+  fnptr(0);
+}
index ceeb0ad5ab3351a77caea5fd6940ea58347d6aab..0ae998f86f9839ba5a95c5fc1a22cd2f12b5cdad 100644 (file)
@@ -1512,10 +1512,12 @@ eliminate_unnecessary_stmts (bool aggressive)
        remove_edge (to_remove_edges[i]);
       cfg_altered = true;
     }
-  /* When we cleared calls_setjmp we can purge all abnormal edges.  Do so.  */
-  if (cfun->calls_setjmp != had_setjmp)
+  /* When we cleared calls_setjmp we can purge all abnormal edges.  Do so.
+     ???  We'd like to assert that setjmp calls do not pop out of nothing
+     but we currently lack a per-stmt way of noting whether a call was
+     recognized as returns-twice (or rather receives-control).  */
+  if (!cfun->calls_setjmp && had_setjmp)
     {
-      gcc_assert (!cfun->calls_setjmp);
       /* Make sure we only remove the edges, not dominated blocks.  Using
         gimple_purge_dead_abnormal_call_edges would do that and we
         cannot free dominators yet.  */