From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 46A7F395383D; Tue, 2 May 2023 20:16:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46A7F395383D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058589; bh=ywAieVxMLXHj8cIhnvgutYnKnjcKxiNiLUG/agXP1ck=; h=From:To:Subject:Date:From; b=Gy3ncQ5zS8BDJN/X8/k0PKRqw+EQ2tyWxVcPLQkl5f0OMloiod+Lz+TRNlUMeTy5Y Ig66MgjPr4IlVp719IeauDY7FL7NLoX9RXl1HKW3VA6A/pZQvS2dH/br2GmUzlBVAq zkqLkzMDMzFyXMkE4HFLz803Qfu/rwdqpTdX0hZE= 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 r11-10732] sanopt: Return TODO_cleanup_cfg if any .{UB, HWA, A}SAN_* calls were lowered [PR106190] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 623245bc3f4eed25db80dd5f5650c18cd7314b39 X-Git-Newrev: b6d67e397215fbfc408d0282be4522895717bf74 Message-Id: <20230502201629.46A7F395383D@sourceware.org> Date: Tue, 2 May 2023 20:16:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b6d67e397215fbfc408d0282be4522895717bf74 commit r11-10732-gb6d67e397215fbfc408d0282be4522895717bf74 Author: Jakub Jelinek Date: Tue Mar 28 10:56:44 2023 +0200 sanopt: Return TODO_cleanup_cfg if any .{UB,HWA,A}SAN_* calls were lowered [PR106190] The following testcase ICEs, because without optimization eh lowering decides not to duplicate finally block of try/finally and so we end up with variable guarded cleanup. The sanopt pass creates a cfg that ought to be cleaned up (some IFN_UBSAN_* functions are lowered in this case with constant conditions in gcond and when not allowing recovery some bbs which end with noreturn calls actually have successor edges), but the cfg cleanup is actually (it is -O0) done only during the optimized pass. We notice there that the d[1][a] = 0; statement which has an EH edge is unreachable (because ubsan would always abort on the out of bounds d[1] access), remove the EH landing pad and block, but because that block just sets a variable and jumps to another one which tests that variable and that one is reachable from normal control flow, the __builtin_eh_pointer (1) later in there is kept in the IL and we ICE during expansion of that statement because the EH region has been removed. The following patch fixes it by doing the cfg cleanup already during sanopt pass if we create something that might need it, while the EH landing pad is then removed already during sanopt pass, there is ehcleanup later and we don't ICE anymore. 2023-03-28 Jakub Jelinek PR middle-end/106190 * sanopt.c (pass_sanopt::execute): Return TODO_cleanup_cfg if any of the IFN_{UB,HWA,A}SAN_* internal fns are lowered. * gcc.dg/asan/pr106190.c: New test. (cherry picked from commit 39a43dc336561e0eba0de477b16c7355f19d84ee) Diff: --- gcc/sanopt.c | 6 +++++- gcc/testsuite/gcc.dg/asan/pr106190.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/sanopt.c b/gcc/sanopt.c index 2910e33c1cc..f29f07c79f1 100644 --- a/gcc/sanopt.c +++ b/gcc/sanopt.c @@ -1275,6 +1275,7 @@ pass_sanopt::execute (function *fun) basic_block bb; int asan_num_accesses = 0; bool contains_asan_mark = false; + int ret = 0; /* Try to remove redundant checks. */ if (optimize @@ -1327,6 +1328,7 @@ pass_sanopt::execute (function *fun) if (gimple_call_internal_p (stmt)) { enum internal_fn ifn = gimple_call_internal_fn (stmt); + int this_ret = TODO_cleanup_cfg; switch (ifn) { case IFN_UBSAN_NULL: @@ -1362,8 +1364,10 @@ pass_sanopt::execute (function *fun) no_next = hwasan_expand_mark_ifn (&gsi); break; default: + this_ret = 0; break; } + ret |= this_ret; } else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { @@ -1393,7 +1397,7 @@ pass_sanopt::execute (function *fun) if (need_commit_edge_insert) gsi_commit_edge_inserts (); - return 0; + return ret; } } // anon namespace diff --git a/gcc/testsuite/gcc.dg/asan/pr106190.c b/gcc/testsuite/gcc.dg/asan/pr106190.c new file mode 100644 index 00000000000..10eb2789a49 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr106190.c @@ -0,0 +1,15 @@ +/* PR middle-end/106190 */ +/* { dg-do compile } */ +/* { dg-options "-fnon-call-exceptions -fsanitize=address,undefined -fno-sanitize-recover=all" } */ + +int +main () +{ + int a; + int *b[1]; + int c[10]; + int d[1][1]; + for (a = 0; a < 1; a++) + d[1][a] = 0; + return 0; +}