https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124270
Bug ID: 124270
Summary: Optimizer folds constexpr routine into wrong value for
aarch64-elf
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: josh.a.seaton at gmail dot com
Target Milestone: ---
```
$ aarch64-elf-g++ --version
aarch64-elf-g++ (https://gnu.googlesource.com/gcc
c3823ed4bb066ca4dd13be502f45b463a6bf3d1b) 15.2.1 20260221
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
This issue reproduces with
```
extern "C" {
void panic() __attribute__((__noreturn__));
}
struct FooValueWrapper {
bool value = false;
};
class FooValueSetter {
public:
constexpr FooValueSetter(FooValueWrapper* wrapper) {
if (wrapper->value) {
panic();
}
wrapper->value = true;
}
};
struct Foo {
constexpr Foo& self() { return *this; }
FooValueWrapper wrapper;
FooValueSetter setter{&wrapper};
};
int main() { Foo{}.self(); return 0; }
```
and
```
aarch64-elf-g++ -c reproducer.cc -S -o - -O1
.arch armv8-a
.file "reproducer.cc"
.text
.align 2
.global main
.type main, %function
main:
.LFB4:
.cfi_startproc
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_offset 29, -16
.cfi_offset 30, -8
mov x29, sp
bl panic
.cfi_endproc
.LFE4:
.size main, .-main
.ident "GCC: (https://gnu.googlesource.com/gcc
f0f35f35e3a96dc15bd242e0bbb1db0096b8213f) 15.2.1 20260131"
```
which leads to a spurious call to `panic()`.