From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id AD6343858D28; Sun, 21 Apr 2024 04:09:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD6343858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713672554; bh=2n0J698O1iHmXxmhd8wioyavZQuYGpprPJPtE/BF53U=; h=From:To:Subject:Date:From; b=O+4AQQ6cXRypIAUjXNsQf+lOqCWZF3QKHczolRGv7iHK7mbNYoa5XOHEeOPwhdoST q0rNLOwWQ7IrpcXSoxKlD5rBSTNKmAfQ9+JV5B6qaOiHz1Pow/QlvOZRJas5SLLVIo 4yZUbVviAkfXvIDI1wWHHNQo7EcH63KFW0NQth/c= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8631] Limit special asan/ubsan/bitint returns_twice handling to calls in bbs with abnormal pred [PR114687] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: a16d90ec302e588dab5d7d31ccdd7b3fd5c6214e X-Git-Newrev: 7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e Message-Id: <20240421040914.AD6343858D28@sourceware.org> Date: Sun, 21 Apr 2024 04:09:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e commit r13-8631-g7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e Author: Jakub Jelinek 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 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. * gcc.dg/asan/pr114687.c: New test. (cherry picked from commit c9e94ae448ba309dba74de3ee1974a3ed9248889) Diff: --- gcc/gimple-iterator.cc | 6 ++++-- gcc/testsuite/gcc.dg/asan/pr114687.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-iterator.cc b/gcc/gimple-iterator.cc index 07a77ca2a77..ee1081dec1a 100644 --- a/gcc/gimple-iterator.cc +++ b/gcc/gimple-iterator.cc @@ -1048,7 +1048,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); @@ -1071,7 +1072,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/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; +}