public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9933] Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687]
@ 2024-04-12  9:00 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-04-12  9:00 UTC (permalink / raw)
  To: gcc-cvs

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

commit r14-9933-gc9e94ae448ba309dba74de3ee1974a3ed9248889
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 12 10:59:54 2024 +0200

    Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687]
    
    The tree-cfg.cc verifier only diagnoses returns_twice calls preceded
    by non-label/debug stmts if it is in a bb with abnormal predecessor.
    The following testcase shows that if a user lies in the attributes
    (a function which never returns can't be pure, and can't return
    twice when it doesn't ever return at all), when we figure it out,
    we can remove the abnormal edges to the "returns_twice" call and perhaps
    whole .ABNORMAL_DISPATCHER etc.
    edge_before_returns_twice_call then ICEs because it can't find such
    an edge.
    
    The following patch limits the special handling to calls in bbs where
    the verifier requires that.
    
    2024-04-12  Jakub Jelinek  <jakub@redhat.com>
    
            PR sanitizer/114687
            * gimple-iterator.cc (gsi_safe_insert_before): Only use
            edge_before_returns_twice_call if bb_has_abnormal_pred.
            (gsi_safe_insert_seq_before): Likewise.
            * gimple-lower-bitint.cc (bitint_large_huge::lower_call): Only
            push to m_returns_twice_calls if bb_has_abnormal_pred.
    
            * gcc.dg/asan/pr114687.c: New test.

Diff:
---
 gcc/gimple-iterator.cc               |  6 ++++--
 gcc/gimple-lower-bitint.cc           |  2 +-
 gcc/testsuite/gcc.dg/asan/pr114687.c | 22 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-iterator.cc b/gcc/gimple-iterator.cc
index ac6cb4aa414..93646262eac 100644
--- a/gcc/gimple-iterator.cc
+++ b/gcc/gimple-iterator.cc
@@ -1049,7 +1049,8 @@ gsi_safe_insert_before (gimple_stmt_iterator *iter, gimple *g)
   gimple *stmt = gsi_stmt (*iter);
   if (stmt
       && is_gimple_call (stmt)
-      && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0)
+      && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0
+      && bb_has_abnormal_pred (gsi_bb (*iter)))
     {
       edge e = edge_before_returns_twice_call (gsi_bb (*iter));
       basic_block new_bb = gsi_insert_on_edge_immediate (e, g);
@@ -1072,7 +1073,8 @@ gsi_safe_insert_seq_before (gimple_stmt_iterator *iter, gimple_seq seq)
   gimple *stmt = gsi_stmt (*iter);
   if (stmt
       && is_gimple_call (stmt)
-      && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0)
+      && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0
+      && bb_has_abnormal_pred (gsi_bb (*iter)))
     {
       edge e = edge_before_returns_twice_call (gsi_bb (*iter));
       gimple *f = gimple_seq_first_stmt (seq);
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 4c3b7f7b68e..7e8b6e3c51a 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -5320,7 +5320,7 @@ bitint_large_huge::lower_call (tree obj, gimple *stmt)
 	  arg = make_ssa_name (TREE_TYPE (arg));
 	  gimple *g = gimple_build_assign (arg, v);
 	  gsi_insert_before (&gsi, g, GSI_SAME_STMT);
-	  if (returns_twice)
+	  if (returns_twice && bb_has_abnormal_pred (gimple_bb (stmt)))
 	    {
 	      m_returns_twice_calls.safe_push (stmt);
 	      returns_twice = false;
diff --git a/gcc/testsuite/gcc.dg/asan/pr114687.c b/gcc/testsuite/gcc.dg/asan/pr114687.c
new file mode 100644
index 00000000000..48cc8688176
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr114687.c
@@ -0,0 +1,22 @@
+/* PR sanitizer/114687 */
+/* { dg-do compile } */
+
+int a;
+int foo (int);
+
+__attribute__((pure, returns_twice)) int
+bar (void)
+{
+  a = 1;
+  while (a)
+    a = 2;
+  return a;
+}
+
+int
+baz (void)
+{
+  int d = bar ();
+  foo (d);
+  return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-12  9:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12  9:00 [gcc r14-9933] Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687] Jakub Jelinek

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).