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

            Bug ID: 127527
           Summary: ICE: segfault in c_finish_bc_name on a malformed
                    switch/for/break sequence (named loops)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: captainnemo9292 at gmail dot com
  Target Milestone: ---
            Target: x86_64-linux-gnu

The named-break/continue code introduced for C2Y named loops dereferences
a null pointer when the enclosing statement failed to parse:

  void b() { switch case : for break a }

  $ gcc -c t.c
  t.c:1:19: error: expected '(' before 'case'
  t.c:1:24: internal compiler error: Segmentation fault
  c_finish_bc_name(unsigned long, tree_node*, bool)
  c_parse_file()
  https://godbolt.org/z/droP7YP9W

'break a' looks up the label 'a' in the enclosing loop/switch stack, but the
switch statement never got a body/condition, so the entry it finds is empty.
gcc trunk 17.0.0 20260920; gcc 13 (before named loops) only reports the
syntax errors.

Reply via email to