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

            Bug ID: 113545
           Summary: ICE in label_matches with constexpr function with
                    switch-statement and converted (nonconstant, cast
                    address) input
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hp at gcc dot gnu.org
  Target Milestone: ---

For the following test-case, g++ ICEs from at least gcc-10 and forward (i.e.
apparently not a regression):
```
char foo;

constexpr unsigned char bar(__UINTPTR_TYPE__ baz)
{
  switch (baz)
    {
    case 13:
      return 11;
    case 14:
      return 78;
    case 2048:
      return 13;
    default:
      return 42;
    }
}

__attribute__ ((__noipa__))
void xyzzy(int x)
{
  if (x != 42)
    __builtin_abort ();
}

int main()
{
  unsigned const char c = bar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
  xyzzy(c);
}
'''

Example backtrace with -std=c++20 -O3:

../n.cc: In function 'int main()':
../n.cc:27:30:   in 'constexpr' expansion of 'bar(((long unsigned int)(&
foo)))'
../n.cc:5:3: internal compiler error: in label_matches, at cp/constexpr.cc:6925
    5 |   switch (baz)
      |   ^~~~~~
0x63894c label_matches
        /gcctop/gcc/cp/constexpr.cc:6925
0xa0bb3d cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:7319
0xa0d2b2 cxx_eval_statement_list
        /gcctop/gcc/cp/constexpr.cc:6969
0xa0d2b2 cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:8316
0xa1e782 cxx_eval_switch_expr
        /gcctop/gcc/cp/constexpr.cc:7115
0xa0cb6b cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:8412
0xa0aae6 cxx_eval_call_expression
        /gcctop/gcc/cp/constexpr.cc:3288
0xa0c2ef cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:7524
0xa17d9a cxx_eval_outermost_constant_expr
        /gcctop/gcc/cp/constexpr.cc:8822
0xa1d28f maybe_constant_value(tree_node*, tree_node*, mce_value)
        /gcctop/gcc/cp/constexpr.cc:9110
0xa49e40 cp_fully_fold
        /gcctop/gcc/cp/cp-gimplify.cc:2831
0xa49ed9 cp_fully_fold
        /gcctop/gcc/cp/cp-gimplify.cc:2825
0xa49ed9 cp_fully_fold_init(tree_node*)
        /gcctop/gcc/cp/cp-gimplify.cc:2861
0xc7a204 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        /gcctop/gcc/cp/typeck2.cc:926
0xa6ca32 check_initializer
        /gcctop/gcc/cp/decl.cc:7810
0xa941be cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        /gcctop/gcc/cp/decl.cc:8842
0xb95477 cp_parser_init_declarator
        /gcctop/gcc/cp/parser.cc:23618
0xb6ac98 cp_parser_simple_declaration
        /gcctop/gcc/cp/parser.cc:15890
0xb8f830 cp_parser_declaration_statement
        /gcctop/gcc/cp/parser.cc:14926
0xb97215 cp_parser_statement
        /gcctop/gcc/cp/parser.cc:12882
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.

Reply via email to