From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 783F7385840E; Thu, 27 Apr 2023 13:19:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 783F7385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682601540; bh=+ySJYt5657FLwUmeVg5TUpX4F9UF7FDaJk8tLukH76Q=; h=From:To:Subject:Date:From; b=e5cLYLyFozTrTBstY3gZVUPheK+CnYCZmMFDBPN9rXSrmqg0VPvKFx0MBrpgPQl0n ZnlrQLHX5AwWrRcZocfoEnE5OLsJVuRaOUy+jgGhHLNec/8tUw33+diinBIUEJCy2u tcqOmoXwwI5ezjBL0Is0wVC221EEFzYvIywi/AUM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9480] PR rtl-optimization/106421: ICE in bypass_block from non-local goto. X-Act-Checkin: gcc X-Git-Author: Roger Sayle X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 37da428922e5cb548430aa00482d6a4c7aa8f8b2 X-Git-Newrev: 0a5fb0ee337b824224a2c13b76fd682b62e6d314 Message-Id: <20230427131900.783F7385840E@sourceware.org> Date: Thu, 27 Apr 2023 13:19:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0a5fb0ee337b824224a2c13b76fd682b62e6d314 commit r12-9480-g0a5fb0ee337b824224a2c13b76fd682b62e6d314 Author: Roger Sayle Date: Tue Jan 10 14:05:46 2023 +0000 PR rtl-optimization/106421: ICE in bypass_block from non-local goto. This patch fixes PR rtl-optimization/106421, an ICE-on-valid (but undefined) regression. The fix, as proposed by Richard Biener, is to defend against BLOCK_FOR_INSN returning NULL in cprop's bypass_block. 2023-01-10 Roger Sayle gcc/ChangeLog PR rtl-optimization/106421 * cprop.cc (bypass_block): Check that DEST is local to this function (non-NULL) before calling find_edge. gcc/testsuite/ChangeLog PR rtl-optimization/106421 * gcc.dg/pr106421.c: New test case. (cherry picked from commit 851e1ba03f9de699a754dd8648fc151c3e26d697) Diff: --- gcc/cprop.cc | 9 ++++++--- gcc/testsuite/gcc.dg/pr106421.c | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/cprop.cc b/gcc/cprop.cc index cf01c2d79a9..2a99553a5a5 100644 --- a/gcc/cprop.cc +++ b/gcc/cprop.cc @@ -1622,9 +1622,12 @@ bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump) { dest = BLOCK_FOR_INSN (XEXP (new_rtx, 0)); /* Don't bypass edges containing instructions. */ - edest = find_edge (bb, dest); - if (edest && edest->insns.r) - dest = NULL; + if (dest) + { + edest = find_edge (bb, dest); + if (edest && edest->insns.r) + dest = NULL; + } } else dest = NULL; diff --git a/gcc/testsuite/gcc.dg/pr106421.c b/gcc/testsuite/gcc.dg/pr106421.c new file mode 100644 index 00000000000..73e522afc10 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106421.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int main(int argc, char **argv) +{ + __label__ loop, end; + void jmp(int c) { goto *(c ? &&loop : &&end); } +loop: + jmp(argc < 0); +end: + return 0; +} +