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

            Bug ID: 90017
           Summary: gcc generates wrong debug information at -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 seems to be a recent regression, starting at r269302.
It only affects "-O3" and trunk.
The correct value is "l=0". With -O3, it generates l=8.


$ gcc-trunk -v
gcc version 9.0.1 20190408 (experimental) [trunk revision 270202] (GCC)

#correct output#
$ gcc-trunk -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004a5: file abc.c, line 15.

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

#wrong output#
$ gcc-trunk -g abc.c -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400470: file abc.c, line 15.

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







$ cat abc.c
__attribute__((noipa))  optimize_me_not(){
   __asm__ volatile ("" : : : "memory");
 }

int a, b;
int c[][2] = {{2}, {5}, 2};
int main() {
  {
    int l;
    for (; b <= 1; b++) {
      l = 0;
      for (; l <= 8; l++) {
        a ^= c[b + 1][b];
        if (a)
          optimize_me_not();
      }
    }
  }
}


$ cat cmds
b 15
r
p l
k
q

Reply via email to