Bug 115787 - [GIMPLE-FE] ICE: in gimple_build_switch_nlabels, at gimple.cc:807
Summary: [GIMPLE-FE] ICE: in gimple_build_switch_nlabels, at gimple.cc:807
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks: gimplefe
  Show dependency treegraph
 
Reported: 2024-07-04 17:44 UTC by Anonymous
Modified: 2024-07-05 06:00 UTC (History)
0 users

See Also:
Host:
Target: x86_64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-07-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anonymous 2024-07-04 17:44:25 UTC
*******************************************************************************
The compiler produces a segfault during gimple_build_switch_nlabels at gimple.cc807 when compiling the provided code with the specified options. 
The issue can also be reproduced on Compiler Explorer.

*******************************************************************************
OS and Platform:
# uname -a
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/root/gdbtest/gcc/gcc-15/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /root/gdbtest/gcc/obj/../gcc/configure --prefix=/root/gdbtest/gcc/gcc-15 --enable-languages=c,c++,fortran,go --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240509 (experimental) (GCC) 
*******************************************************************************
Program:
# cat test035.c
__GIMPLE a(argc) {
  switch (argc_20) {
  case 1:
    b;
  }


*******************************************************************************
Command Lines:
# gcc test035.c -O2 -fdump-tree-gimple -fdump-tree-switchconv -Wall -c -o test035.o
test035.c:1:1: error: ‘__GIMPLE’ only valid with ‘-fgimple’
    1 | __GIMPLE a(argc) {
      | ^~~~~~~~
test035.c:1:10: error: return type defaults to ‘int’ [-Wimplicit-int]
    1 | __GIMPLE a(argc) {
      |          ^
test035.c: In function ‘a’:
test035.c:1:10: error: type of ‘argc’ defaults to ‘int’ [-Wimplicit-int]
test035.c:5:3: internal compiler error: in gimple_build_switch_nlabels, at gimple.cc:807
    5 |   }
      |   ^
0x7e5713 gimple_build_switch_nlabels(unsigned int, tree_node*, tree_node*)
        /root/gdbtest/gcc/obj/../gcc/gcc/gimple.cc:807
0x7e5713 gimple_build_switch_nlabels(unsigned int, tree_node*, tree_node*)
        /root/gdbtest/gcc/obj/../gcc/gcc/gimple.cc:804
0xd09040 gimple_build_switch(tree_node*, tree_node*, vec<tree_node*, va_heap, vl_ptr> const&)
        /root/gdbtest/gcc/obj/../gcc/gcc/gimple.cc:827
0xa64ac1 c_parser_gimple_switch_stmt
        /root/gdbtest/gcc/obj/../gcc/gcc/c/gimple-parser.cc:2552
0xa64ac1 c_parser_gimple_compound_statement
        /root/gdbtest/gcc/obj/../gcc/gcc/c/gimple-parser.cc:440
0xa64d61 c_parser_parse_gimple_body(c_parser*, char*, c_declspec_il, profile_count)
        /root/gdbtest/gcc/obj/../gcc/gcc/c/gimple-parser.cc:253
0xa505a4 c_parser_declaration_or_fndef
        /root/gdbtest/gcc/obj/../gcc/gcc/c/c-parser.cc:3011
0xa5af4b c_parser_external_declaration
        /root/gdbtest/gcc/obj/../gcc/gcc/c/c-parser.cc:2046
0xa5b935 c_parser_translation_unit
        /root/gdbtest/gcc/obj/../gcc/gcc/c/c-parser.cc:1900
0xa5b935 c_parse_file()
        /root/gdbtest/gcc/obj/../gcc/gcc/c/c-parser.cc:26889
0xad3a51 c_common_parse_file()
        /root/gdbtest/gcc/obj/../gcc/gcc/c-family/c-opts.cc:1311
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

*******************************************************************************

Also ICE on trunk, compiler explorer:https://godbolt.org/z/5sYY7a47c

*******************************************************************************
Comment 1 Richard Biener 2024-07-05 06:00:16 UTC
With a better testcase error-recovery could be avoided.  Note that the GIMPLE parser doesn't impose all GIMPLE constraints but relies on the verifier.  This
IL part (default label present) is instead verified by an assert.