public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1408] tree-optimization: only DSE trapping insn if -fdelete-dead-exceptions
Date: Sun,  3 Jul 2022 00:34:28 +0000 (GMT)	[thread overview]
Message-ID: <20220703003428.A9E66385742B@sourceware.org> (raw)

https://gcc.gnu.org/g:d86a20ee8bed8840d39ab781c935a411e28fa0b6

commit r13-1408-gd86a20ee8bed8840d39ab781c935a411e28fa0b6
Author: Ian Lance Taylor <iant@golang.org>
Date:   Fri Jul 1 14:51:45 2022 -0700

    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.

Diff:
---
 gcc/testsuite/g++.dg/torture/except-1.C | 44 +++++++++++++++++++++++++++++++++
 gcc/tree-ssa-dse.cc                     |  3 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/torture/except-1.C b/gcc/testsuite/g++.dg/torture/except-1.C
new file mode 100644
index 00000000000..7050a33cc27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/except-1.C
@@ -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;
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index 62efafe384d..8d1739a4510 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -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);
 }


                 reply	other threads:[~2022-07-03  0:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220703003428.A9E66385742B@sourceware.org \
    --to=ian@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).