https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92387
Bug ID: 92387
Summary: gcc generates wrong debug information at -O1
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 seems to be a recent regression. gcc-9 works fine.
The expected value of i should be 0 or opt-out. However, with "-O1", gdb
outputs "i=1".
$ gcc-trunk -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191105 (experimental) [trunk revision 277821] (GCC)
#expected output
$ gcc-trunk -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400540: file abc.c, line 12.
Breakpoint 1, main () at abc.c:12
12 if (d) printf("index = %d\n", i); // stop here.
$1 = 0
#wrong output at -O1
$ gcc-trunk -O1 -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004a1: file abc.c, line 12.
Breakpoint 1, main () at abc.c:12
12 if (d) printf("index = %d\n", i); // stop here.
$1 = 1
$ cat abc.c
static int a[6];
int b ;
static void c () {
b = 5 ^ a[b & 5];
}
int main () {
int i, d = 0;
c ();
i = 0;
for (; i < 8; i++) {
c ();
if (d) printf("index = %d\n", i); // stop here.
}
}
$ cat cmds
b abc.c:12
r
p i
kill
q