https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119730
Bug ID: 119730
Summary: Unexpected -Wclobbered with -O2 and local register
variables
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: florian.lugou at provenrun dot com
Target Milestone: ---
On Ubuntu 24.04, tested with aarch64-none-elf GCC 14.2.Rel1 and 15.0.1.
$ cat mwe.i
typedef long long jmp_buf[22];
void longjmp (jmp_buf __jmpb, int __retval)
__attribute__ ((__noreturn__));
int setjmp (jmp_buf __jmpb);
static inline void f(void)
{
register int x0 asm ("x0") = 0;
asm volatile ("svc #0" : : "r" (x0) : "memory");
}
void g(int);
static jmp_buf jmp;
void run_test_case(void)
{
f();
int sj = setjmp(jmp);
if (sj != 0){
g(0);
} else {
g(0);
}
}
$ aarch64-none-elf-gcc -O2 -Wclobbered -v -S mwe.i
Using built-in specs.
Target: aarch64-none-elf
Configured with: ../configure --target=aarch64-none-elf --with-newlib
--disable-gdbtk --disable-libstdcxx --enable-languages=c --disable-libssp
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.1 20250411 (experimental) (GCC)
cc1 -fpreprocessed mwe.i -quiet -dumpbase mwe.i -dumpbase-ext .i
-mlittle-endian -mabi=lp64 -O2 -Wclobbered -version -o mwe.s
GNU C23 (GCC) version 15.0.1 20250411 (experimental) (aarch64-none-elf)
compiled by GNU C version 13.3.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 7f750bb20cb71bdbabbe43664562539a
mwe.i: In function ‘run_test_case’:
mwe.i:10:16: warning: variable ‘x0’ might be clobbered by ‘longjmp’ or ‘vfork’
[-Wclobbered]
10 | register int x0 asm ("x0") = 0;
| ^~