https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128055
Bug ID: 128055
Summary: wrong code at -O1 and above: store is deleted although
it is read back through an __attribute__((alias)) of
the variable
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
int a = 0;
extern int b __attribute__((alias("a")));
__attribute__((noipa)) int f(void) {
a = 1;
int x = b;
a = 2;
return x;
}
int main(void) {
if (f() != 1)
__builtin_abort();
}
godbolt: https://godbolt.org/z/66s8zYosG
b is an alias of a, so f must return 1 and the program must exit normally, as
it does at -O0 and with -O2 -fno-dse. At -O1, -O2, -O3 and -Os the store a = 1
is deleted, f returns 0, and the program aborts.