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

            Bug ID: 129112
           Summary: [17 Regression] link failure at -O1: undefined
                    reference to a static inline function called in an
                    unreachable switch default
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: link-failure
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shimizu2486 at gmail dot com
  Target Milestone: ---

Live reproducer: https://godbolt.org/z/EPzoWoabY

$ cat t1.c
int c;
static inline int d(void) { return 1; }
typedef struct {
  _BitInt(2) v;
} S;
void f(S s) {
  d();
  switch (s.v) {
  case -2:
  case -1:
    break;
  case 0:
  case 1:
    c = s.v;
    break;
  default:
    c = d();
  }
}
int main(void) { S s = {0}; f(s); }

s.v is a _BitInt(2), so it is -2, -1, 0 or 1, and each has a case label: the
default case cannot be reached.
The program should compile, link and exit with 0.

$ gcc -O0 t1.c -o t1 && ./t1; echo $?
0
$ gcc -O1 t1.c -o t1
/usr/bin/ld: /tmp/ccXXXXXX.o: in function `f':
t1.c:(.text+0x1e): undefined reference to `d'
collect2: error: ld returned 1 exit status

  trunk (7be67d007f88)              link failure
  trunk 2026-11-17 (bb273fcdc094)   link failure
  trunk 2026=11-16 (303400bda9e3)   links
  16.2.0                            links

-O1 fails, but -O0, -Og, -O2, -O3 and -Os link.
-fno-tree-sra, -fno-early-inlining or -fno-inline makes -O1 link.

Reply via email to