diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2023-01-10 14:05:46 +0000 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-04-27 13:57:48 +0200 |
commit | 0a5fb0ee337b824224a2c13b76fd682b62e6d314 (patch) | |
tree | c837e621b11d9a1a99cbf83fa211705ff17a36d6 | |
parent | 37da428922e5cb548430aa00482d6a4c7aa8f8b2 (diff) | |
download | gcc-0a5fb0ee337b824224a2c13b76fd682b62e6d314.zip gcc-0a5fb0ee337b824224a2c13b76fd682b62e6d314.tar.gz gcc-0a5fb0ee337b824224a2c13b76fd682b62e6d314.tar.bz2 |
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 <roger@nextmovesoftware.com>
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)
-rw-r--r-- | gcc/cprop.cc | 9 | ||||
-rw-r--r-- | 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 cf01c2d..2a99553 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 0000000..73e522a --- /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; +} + |