https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127131

            Bug ID: 127131
           Summary: ICE: tree check: expected class 'type', have
                    'exceptional' (error_mark) in
                    useless_type_conversion_p, at gimple-expr.cc:85, when
                    calling a member function on the loop variable of a
                    `template for` expansion statement
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jasio.lpn at gmail dot com
  Target Milestone: ---

Compiling the following code crashes the compiler with an ICE during
gimplification:

=== ice.cpp ===
struct Thing
{
    constexpr int value() const { return 1; }
};

constexpr Thing items[] = { Thing{} };

int main()
{
    template for (constexpr Thing item: items) {
        auto v = item.value();
    }
}

=== Command ===
g++ -std=gnu++26 -c ice.cpp

=== Output ===
ice.cpp: In function ‘int main()’:
ice.cpp:8:5: internal compiler error: tree check: expected class ‘type’, have
‘exceptional’ (error_mark) in useless_type_conversion_p, at gimple-expr.cc:85
    8 | int main()
      |     ^~~~
0x2a2881f internal_error(char const*, ...)
        ../../source/gcc/diagnostic-global-context.cc:787
0x679ac8 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ../../source/gcc/tree.cc:9291
0x574130 tree_class_check(tree_node*, tree_code_class, char const*, int, char
const*)
        ../../source/gcc/tree.h:3986
0x574130 useless_type_conversion_p(tree_node*, tree_node*)
        ../../source/gcc/gimple-expr.cc:85
0x12bc189 verify_gimple_assign_single
        ../../source/gcc/tree-cfg.cc:4551
0x12bc189 verify_gimple_assign
        ../../source/gcc/tree-cfg.cc:4808
0x12bc189 verify_gimple_stmt
        ../../source/gcc/tree-cfg.cc:5082
0x12bd277 verify_gimple_in_seq_2
        ../../source/gcc/tree-cfg.cc:5251
0x12bd24c verify_gimple_in_seq_2
        ../../source/gcc/tree-cfg.cc:5242
0x12bd2b8 verify_gimple_in_seq_2
        ../../source/gcc/tree-cfg.cc:5215
0x12bd2b8 verify_gimple_in_seq_2
        ../../source/gcc/tree-cfg.cc:5215
0x12bd331 verify_gimple_in_seq(gimple*, bool)
        ../../source/gcc/tree-cfg.cc:5290
0xef3a4a gimplify_body(tree_node*, bool)
        ../../source/gcc/gimplify.cc:21906
0xef3c8e gimplify_function_tree(tree_node*)
        ../../source/gcc/gimplify.cc:22032
0xc8d39f cgraph_node::analyze()
        ../../source/gcc/cgraphunit.cc:691
0xc902c7 analyze_functions
        ../../source/gcc/cgraphunit.cc:1270
0xc91362 symbol_table::finalize_compilation_unit()
        ../../source/gcc/cgraphunit.cc:2593
/opt/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1plus -quiet
-D_GNU_SOURCE ice.cpp -quiet -dumpbase ice.cpp -dumpbase-ext .cpp
-mtune=generic -march=x86-64 -std=gnu++26 -o /tmp/cctEMdTm.s
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.

=== Additional info ===
Looks like regression - not reproducible with the distro's GCC 16.2 - the same
source compiles cleanly there. The ICE only occurs with the 17.0.0 20260829
(experimental)

=== Tested compilers ===
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/gcc-trunk
--enable-languages=c,c++ --disable-bootstrap --disable-multilib
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260829 (experimental) (GCC) 


Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,cobol,algol68,lto
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugzilla.redhat.com/ --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-16.2.1-build/gcc-16.2.1-20260819/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-tls=gnu2 --with-arch_32=i686
--build=x86_64-redhat-linux --with-build-config=bootstrap-lto
--enable-link-serialization=1 --disable-libssp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260819 (Red Hat 16.2.1-2) (GCC)

Reply via email to