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

            Bug ID: 123543
           Summary: [16 Regression] ipa miscompiles python-3.13.11,
                    libgit2-1.9.2, graphite2-1.3.14 since
                    r16-6652-ge58b11cd6c9ca3
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

I originally noticed the bug on recent gcc-master as a python-3.13.11,
libgit2-1.9.2, graphite2-1.3.14 build (or test) failure. I bisected `gcc` down
to r16-6652-ge58b11cd6c9ca3 and extracted minimal example from libgit2-1.9.2.

The reproducer seems to require 2 files (I suspect `noipa` has no effect and
it's probably a bug). Reproducer:

//$ cat a.c
__attribute__((noinline)) static int    local_f(int a, int b) { return a + b; }
__attribute__((noinline))        int   extern_f(int a, int b) { return
local_f(a, b); }
__attribute__((noipa))           int  unused_g1(int b) { return extern_f(0, b);
}

//$ cat b.c
#include <stdio.h>
extern int extern_f(int a, int b);
int main() { printf("%i\n", extern_f(1, 2)); }

Running:

$ gcc/xgcc -Bgcc a.c b.c -o a -O2 && ./a
3 # good

$ gcc/xgcc -Bgcc a.c b.c -o a -O3 && ./a
2 # bad

Note: we sum up 1+2 here. My speculation is that somehow presence of
`extern_f(0, b)` call tricks IPA into considering `extern_f` as local with the
first parameter always being `0`.

gcc/xgcc -Bgcc -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xgcc
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer --enable-languages=c
CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0' LDFLAGS='-O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20260111 (experimental) (GCC)

Reply via email to