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

            Bug ID: 124562
           Summary: internal compiler error: crash in
                    mangle_template_parm_object with invalid non-type
                    class template argument
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-checking, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

The following code causes ICE out on x86-64 gcc since version 11.1(assertions)
with "-std=c++20" and reproducible on trunk:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct g { char chars[0]; };

template <g str> struct name {};

name<{"hi"}>;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please check: https://godbolt.org/z/GcGY6v4aj

GCC ICEs in mangle_template_parm_object when forming the non-type template
argument {"hi"} for template<g str> struct name; where g contains a zero-length
char[0] member.

Compiler Output:

<source>:5:12: error: initializer-string for 'char [0]' is too long
[-fpermissive]
    5 | name<{"hi"}>;
      |            ^
<source>:5:12: internal compiler error: Segmentation fault
0x2967c58 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x295c89b internal_error(char const*, ...)
        ???:0
0xc8a767 mangle_template_parm_object(tree_node*)
        ???:0
0xdb95c3 coerce_template_parms(tree_node*, tree_node*, tree_node*, int, bool)
        ???:0
0xda59c2 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int)
        ???:0
0xe0c11c finish_template_type(tree_node*, tree_node*, int)
        ???:0
0xd6f213 c_parse_file()
        ???:0
0xef9739 c_common_parse_file()
        ???:0
/cefs/7e/7ed4f94b033d007fdcd4f879_gcc-trunk-20260318/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/7e/7ed4f94b033d007fdcd4f879_gcc-trunk-20260318/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -std=c++20
-fdiagnostics-color=always -fno-verbose-asm -o /app/output.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.
Compiler returned: 1

Reply via email to