DSE patch RFA: Don't delete trapping insn
Commit Message
The DSE pass can delete a dead store even if the instruction can trap.
That is incorrect when using -fnon-call-exceptions
-fno-delete-dead-exceptions. This led to a bug report against gccgo:
https://go.dev/issue/53012. However, the bug is not specific to Go.
This patch fixes the problem in a simple way, and includes a C++
testcase. Bootstrapped and ran C, C++, and Go tests on
x86_64-pc-linux-gnu.
OK for mainline?
Ian
From bae426745756896ec0ea27c9e12469c53b88d538 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <iant@golang.org>
Date: Fri, 1 Jul 2022 14:51:45 -0700
Subject: [PATCH] tree-optimization: only DSE trapping insn if
-fdelete-dead-exceptions
gcc/ChangeLog:
* tree-ssa-dse.cc (dse_optimize_stmt): Only delete a trapping
statement if -fdelete-dead-exceptions.
gcc/testsuite/ChangeLog:
* g++.dg/torture/except-1.C: New test.
---
gcc/testsuite/g++.dg/torture/except-1.C | 44 +++++++++++++++++++++++++
gcc/tree-ssa-dse.cc | 3 +-
2 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/torture/except-1.C
Comments
On 7/1/2022 4:04 PM, Ian Lance Taylor via Gcc-patches wrote:
> The DSE pass can delete a dead store even if the instruction can trap.
> That is incorrect when using -fnon-call-exceptions
> -fno-delete-dead-exceptions. This led to a bug report against gccgo:
> https://go.dev/issue/53012. However, the bug is not specific to Go.
>
> This patch fixes the problem in a simple way, and includes a C++
> testcase. Bootstrapped and ran C, C++, and Go tests on
> x86_64-pc-linux-gnu.
>
> OK for mainline?
OK
jeff
new file mode 100644
@@ -0,0 +1,44 @@
+// { dg-do run { target { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } }
+// { dg-additional-options "-fexceptions -fnon-call-exceptions -fno-delete-dead-exceptions" }
+
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+sighandler (int signo, siginfo_t* si, void* uc)
+{
+ throw (5);
+}
+
+struct S { void *p1, *p2; };
+
+struct S v;
+
+__attribute__ ((noinline))
+int
+dosegv ()
+{
+ struct S *p = 0;
+ struct S s __attribute__((unused)) = *p;
+ return 0;
+}
+
+int main ()
+{
+ struct sigaction sa;
+
+ memset (&sa, 0, sizeof sa);
+ sa.sa_sigaction = sighandler;
+ sigaction (SIGSEGV, &sa, NULL);
+ sigaction (SIGBUS, &sa, NULL);
+
+ try {
+ dosegv ();
+ }
+ catch (int x) {
+ return (x != 5);
+ }
+
+ return 1;
+}
@@ -1463,7 +1463,8 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator *gsi, sbitmap live_bytes)
gimple_call_set_lhs (stmt, NULL_TREE);
update_stmt (stmt);
}
- else
+ else if (!stmt_could_throw_p (fun, stmt)
+ || fun->can_delete_dead_exceptions)
delete_dead_or_redundant_assignment (gsi, "dead", need_eh_cleanup,
need_ab_cleanup);
}