https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88686

            Bug ID: 88686
           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: ---

I have reported this bug at gdb
bugzilla(https://sourceware.org/bugzilla/show_bug.cgi?id=24032). However, it
appears to be a gcc bug. I can reproduce the bug with "gcc version 9.0.0
20190103 (experimental) [trunk revision 267553] (GCC)". The gdb version does
not matter. I can reproduce it with gdb 7.7.

Below is my original report:


=====8<=========
$ gdb-trunk --version
GNU gdb (GDB) 8.2.50.20181223-git

*It correctly prints the value without optimization*
$ gcc-trunk -g  abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400485: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8             optimize_me_not();
9             c = 0;
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 2315) killed]



*It incorrectly prints "j=1" at -O1*
$ gcc-trunk -g -O1  abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400491: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8             optimize_me_not();
10            for (; c < 6; c++)
$1 = 1
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 2331) killed]


*Files used to reproduce*
$ cat abc.c
volatile int a, b;
int c;
int main() {
  int j;
  for (; b < 10; b++) {
    j = 0;
    for (; j < 2; j++) {
      optimize_me_not();
      c = 0;
      for (; c < 6; c++)
        a = b + c;
    }
  }
}
$ cat outer.c
optimize_me_not() {}
$ cat cmds
b 8
r
n
p j
k
q
=====8<=========

Reply via email to