https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127532
Bug ID: 127532
Summary: [GIMPLE FE] goto to an undefined or reserved __BB
crashes the CFG construction (unchecked_make_edge /
find_edge / calc_dfs_tree)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-invalid-code
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: captainnemo9292 at gmail dot com
Target Milestone: ---
Target: x86_64-linux-gnu
The GIMPLE front end does not validate basic-block numbers used in gotos,
so a reference to a block that is never defined (or to the entry block) is
turned into an edge to a null / bogus basic_block and the CFG code crashes.
goto to a block that is never defined:
void __GIMPLE (ssa) a() {
goto __BB6;
}
$ gcc -fgimple -c t.c
t.c:3:1: internal compiler error: Segmentation fault
unchecked_make_edge(basic_block_def*, basic_block_def*, int)
c_parser_parse_gimple_body
https://godbolt.org/z/MEafhsq6T
Same with a defined predecessor (index past the block vector):
void __GIMPLE (ssa) a() { __BB(2): goto __BB3; }
https://godbolt.org/z/b1rh94eaK
Undefined target in a conditional:
void __GIMPLE (ssa) a() { __BB(3): if (1) goto __BB3; else goto __BB4; }
Segmentation fault in find_edge <- make_edge
https://godbolt.org/z/b11fe6v14
goto to the entry block:
void __GIMPLE (ssa) a() { goto __BB0; }
internal compiler error: in calc_dfs_tree_nonrec, at dominance.cc:356
https://godbolt.org/z/d4PTv5GeG
Blocks with no edges at all:
void __GIMPLE (ssa) a() { __BB(2): __BB(3): }
internal compiler error: in calc_dfs_tree, at dominance.cc:458
https://godbolt.org/z/86jrMjqT6
A block number far beyond the number of blocks:
__GIMPLE (ssa) void a() { int b; __BB(39): return b; }
internal compiler error: in vec_safe_grow_cleared, at vec.h:773
https://godbolt.org/z/ErdPq1noo
All on gcc trunk 17.0.0 20260920 with -fgimple; the first three also crash
gcc 13. An "undefined basic block __BBn" error at the goto would cover all of
them.