]> gcc.gnu.org Git - gcc.git/commitdiff
PR rtl-optimization/106421: ICE in bypass_block from non-local goto.
authorRoger Sayle <roger@nextmovesoftware.com>
Tue, 10 Jan 2023 14:05:46 +0000 (14:05 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Tue, 10 Jan 2023 14:05:46 +0000 (14:05 +0000)
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.

gcc/cprop.cc
gcc/testsuite/gcc.dg/pr106421.c [new file with mode: 0644]

index 5b203ecff20bbf00047ebdf280def51554059690..6ec0bda4a243508e1a118be217c8640016d38dd5 100644 (file)
@@ -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 (file)
index 0000000..73e522a
--- /dev/null
@@ -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;
+}
+
This page took 0.07522 seconds and 5 git commands to generate.