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

            Bug ID: 128353
           Summary: internal compiler error: in as_a, at is-a.h:255
           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: haoxintu at gmail dot com
  Target Milestone: ---

Hi,

$cat case.c
struct S { signed char a, b; short c; } __attribute__ ((aligned (4)));
struct S p, q;

int __GIMPLE (ssa,startwith("ifcombine")) __attribute__((noipa))
f1 ()
{
  signed char _1;
  signed char _2;
  int _3;
  int _4;
  int _5;
  int _6;
  signed char _7;
  signed char _8;
  int r;

  __BB(2):
  _1 = p.a;
  _3 = (int) _1;
  _5 = _3 & 127;
  _2 = q.a;
  _4 = (int) _2;
  _6 = _4 & 127;
  if (_5 == q.b)
    goto __BB3;
  else
    goto __BB4;

  __BB(3):
  _7 = p.b;
  _8 = q.b;
  if (_7 == _8)
    goto __BB5;
  else
    goto __BB4;

  __BB(4):
  goto __BB5;

  __BB(5):
  r_9 = __PHI (__BB3: 1, __BB4: 0);
  return r_9;
}

int __GIMPLE (ssa,startwith("ifcombine")) __attribute__((noipa))
f2 ()
{
  signed char _1;
  signed char _2;
  int _3;
  int _4;
  int _5;
  int _6;
  signed char _7;
  signed char _8;
  int r;

  __BB(2):
  _1 = p.a;
  _3 = (int) _1;
  _5 = _3 & 255;
  _2 = q.a;
  _4 = (int) _2;
  _6 = _4 & 255;
  if (_5 == _6)
    goto __BB3;
  else
    goto __BB4;

  __BB(3):
  _7 = p.b;
  _8 = q.b;
  if (_7 == _8)
    goto __BB5;
  else
    goto __BB4;

  __BB(4):
  goto __BB5;

  __BB(5):
  r_9 = __PHI (__BB3: 1, __BB4: 0);
  return r_9;
}

int
main ()
{
  p.a = -1;
  q.a = 127;
  p.b = q.b = -2;
  if (f1 () != 1 || f2 () != 0)
    __builtin_abort ();
  q.b = 2;
  if (f1 () != 0 || f2 () != 0)
    __builtin_abort ();
  q.a = -1;
  q.b = -2;
  if (f1 () != 1 || f2 () != 1)
    __builtin_abort ();
  return 0;
}


$gcc-trunk -fgimple -c case.c
case.c: In function 'f1':
case.c:49:1: internal compiler error: in as_a, at is-a.h:255
   49 | }
      | ^
0x5f0189d internal_error(char const*, ...)
       
/home/haoxin/research/cottontail/gcc/gcc/diagnostic-global-context.cc:787
0x5f1cd18 fancy_abort(char const*, int, char const*)
        /home/haoxin/research/cottontail/gcc/gcc/diagnostics/context.cc:1813
0x1980a67 gimple_statement_with_memory_ops*
as_a<gimple_statement_with_memory_ops*, gimple>(gimple*)
        /home/haoxin/research/cottontail/gcc/gcc/is-a.h:255
0x197c13d gimple_set_vuse(gimple*, tree_node*)
        /home/haoxin/research/cottontail/gcc/gcc/gimple.h:2282
0x27f7860 operands_scanner::finalize_ssa_uses()
        /home/haoxin/research/cottontail/gcc/gcc/tree-ssa-operands.cc:442
0x27f7d49 operands_scanner::finalize_ssa_stmt_operands()
        /home/haoxin/research/cottontail/gcc/gcc/tree-ssa-operands.cc:506
0x27f4ae7 operands_scanner::build_ssa_operands()
        /home/haoxin/research/cottontail/gcc/gcc/tree-ssa-operands.cc:1018
0x27f5810 update_stmt_operands(function*, gimple*)
        /home/haoxin/research/cottontail/gcc/gcc/tree-ssa-operands.cc:1166
0x12218e7 update_stmt(gimple*)
        /home/haoxin/research/cottontail/gcc/gcc/gimple-ssa.h:177
0x120c164 c_parser_parse_gimple_body(c_parser*, char*, c_declspec_il,
profile_count)
        /home/haoxin/research/cottontail/gcc/gcc/c/gimple-parser.cc:385
0x1146695 c_parser_declaration_or_fndef
        /home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:3368
0x1141226 c_parser_external_declaration
        /home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:2276
0x114051a c_parser_translation_unit
        /home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:2115
0x11f6a74 c_parse_file()
        /home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:31603
0x1336078 c_common_parse_file()
        /home/haoxin/research/cottontail/gcc/gcc/c-family/c-opts.cc:1442
/research/cottontail/gcc/build-gcov/install/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1
-quiet -imultiarch x86_64-linux-gnu case.c -quiet -dumpbase case.c
-dumpbase-ext .c -mtune=generic -march=x86-64 -O0 -std=c17 -fgimple -o
/tmp/ccunXdrR.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.


Reproduced in Godbolt: https://godbolt.org/z/KdP3PM9fG

Seems to be a regression since GCC 9.1.

Thanks.

Reply via email to