https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128632
Bug ID: 128632
Summary: wrong code at -O1: IVOPTS stores __imag__ of
big-endian scalar_storage_order complex in native
order
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: reverse-sso, wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
int printf(const char *, ...);
#pragma scalar_storage_order big-endian
struct B { _Complex unsigned c; };
#pragma scalar_storage_order default
struct B g[32];
int n = 4;
int main(void) {
for (int i = 0; i < n; i++) __imag__ g[i].c = i;
printf("%x\n", __imag__ g[2].c);
}
$ gcc -O0 t.c && ./a.out
2
$ gcc -O1 t.c && ./a.out
2000000
Expected: 2. __imag__ g[2].c was set to 2. -O1 stores it byte-swapped. The
array must be large (g[32]).
Suspected cause: IVOPTS may_be_nonaddressable_p does not handle REALPART_EXPR /
IMAGPART_EXPR of a reverse-storage-order struct; the store becomes a
native-order TARGET_MEM_REF.
Avoided by: -fno-ivopts.
Known to fail: 8.5.0, 10.5.0, 11.4.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0,
17.0.
-O0 -fsanitize=undefined,address is clean.
gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release