https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111472
Bug ID: 111472 Summary: Wrong code at -Os on x86_64-linux-gnu since Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch CC: amacleod at redhat dot com Target Milestone: --- gcc at -Os produced the wrong code. Bisected to r11-4563-gd0d8b5d836 Compiler explorer: https://godbolt.org/z/EPznGbaje With -fwrapv the issue goes away. $ cat a.c int printf(const char *, ...); int a, b, e, f; short c = -1, i; char g; int h[4][1] = {8, 5, 8, 5}; int main() { int *j = &e, *k = &f; unsigned short d = c; i = d >> b; *j = i; g = 0; for (; g <= 3; g++) *k = h[(unsigned char)(1 + e) + g][0]; printf("%d\n", f); } $ $ gcc -O0 a.c && ./a.out 5 $ gcc -Os a.c && ./a.out Segmentation fault $ $ gcc -fsanitize=undefined a.c && ./a.out 5 $