[Bug debug/92417] New: gcc generates wrong debug information at -O2

qrzhang at gatech dot edu gcc-bugzilla@gcc.gnu.org
Fri Nov 8 04:53:00 GMT 2019


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

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

It happens at O2 only. "-O1" and "-O3" works fine. It's a recent regression
since "gcc-9 -O2" also works.



The expected value of l_1162[0][0][0] should be 61344 or opt-out. However, with
"-O2", gdb outputs "l_1162[0][0][0]=3".



$ gcc-trunk -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191107 (experimental) [trunk revision 277920] (GCC)

#expected output
$ gcc-trunk -O1 -g abc.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400576: file abc.c, line 23.

Breakpoint 1, n () at abc.c:23
23          if (b)  // optimize_me_not()
$1 = 61344

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

Breakpoint 1, n () at abc.c:23
23          if (b)  // optimize_me_not()
$1 = 3



$ cat abc.c
int a, d, e, f, h, l;
short b, g, i, m;
char c;
void n() {
  char o;
  int p = 0, j, k;
  int q[70] = {0};
  for (; i <= 1; i++) {
    unsigned short l_1162[6][2][2];
    l = 0;
    for (; l < 6; l++) {
      j = 0;
      for (; j < 2; j++) {
        k = 0;
        for (; k < 2; k++)
          l_1162[l][j][k] = 61344;
      }
    }
    for (; f <= 1; f++)
      if (d)
        for (; p >= 0; p--)
          d = q[f];
    if (b)  // optimize_me_not()
      h = l_1162[4][1][0];
    for (; e; e++)
      g = l_1162[5][0][1] <= o;
    c = a ? c : 0;
    q[1] = m;
  }
}
int main() {
  n();
  printf("%X\n");
}



$ cat cmds
b abc.c:23
r
p l_1162[0][0][0]
kill
q


More information about the Gcc-bugs mailing list