https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92468
Bug ID: 92468 Summary: gcc generates wrong debug information at -O2 and -O3 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: qrzhang at gatech dot edu Target Milestone: --- It affects the trunk and both 8 and 9 releases. Gcc-7 works fine. The expected output is k=0 or opt-out. With O2 and O3, gdb outputs k=1. $ gcc-trunk -v gcc version 10.0.0 20191111 (experimental) [trunk revision 278048] (GCC) #expected output $ gcc-trunk -g abc.c $ gdb-trunk -x cmds -batch a.out Breakpoint 1 at 0x40054c: file abc.c, line 20. Breakpoint 1, main () at abc.c:20 20 if (g) printf("index = %d%d%d\n", b, f, k); // optimize_me_not() $1 = 0 #wrong output $ gcc-trunk -g abc.c -O3 $ gdb-trunk -x cmds -batch a.out Breakpoint 1 at 0x4003c0: file abc.c, line 20. Breakpoint 1, main () at abc.c:20 20 if (g) printf("index = %d%d%d\n", b, f, k); // optimize_me_not() $1 = 1 $ cat abc.c int a, b ; short c[5][16] ; void d (e) { a = a ^ e; } int main () { int f, k, g = 0; for (; b < 5; b++) { f = 0; for (; f < 4; f++) { k = 0; for (; k < 4; k++) { d (c[b][f] & c[b][f*4+k] & 5); if (g) printf("index = %d%d%d\n", b, f, k); // optimize_me_not() } } } } $ cat cmds b abc.c:20 r p k kill q