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

            Bug ID: 90716
           Summary: gcc generates wrong debug information at -O2
           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: ---

This is a recent regression. Gcc-8 works fine. Bisect points to r271553.

The expected value of "j" should be 8. With optimization, it prints "0".


$ gcc-trunk -v
gcc version 10.0.0 20190602 (experimental) [trunk revision 271843] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


#Correct output#
$ gcc-trunk -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40049d: file abc.c, line 10.

Breakpoint 1, main () at abc.c:10
10        optimize_me_not();
$1 = 8


#Wrong output at O2#
$ gcc-trunk -g abc.c outer.c -O2
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400396: file abc.c, line 10.

Breakpoint 1, main () at abc.c:10
10        optimize_me_not();
$1 = 0






$ cat abc.c
int a[7][8];
int main() {
  int b, j;
  b = 0;
  for (; b < 7; b++) {
    j = 0;
    for (; j < 8; j++)
      a[b][j] = 0;
  }
  optimize_me_not();
}
$ cat cmds
b 10
r
p j
kill
q
$ cat outer.c
void optimize_me_not() {}

Reply via email to