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

            Bug ID: 92444
           Summary: gcc generates wrong debug information at -O2 and -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. gcc-9 works fine.
The expected output is 1. With "-O2" and "-O3", gdb outputs 8.

$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191110 (experimental) [trunk revision 278017] (GCC)


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

Breakpoint 1, o () at abc.c:46
46      }
$1 = 1

#Wrong output at O2 and O3
$ gcc-trunk -g abc.c -O2
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4005ac: file abc.c, line 45.

Breakpoint 1, o () at abc.c:45
45        }; //     optimize_me_not()
$1 = 8



$ cat abc.c
int a[1];
char b;
char *c = &b;
int d, h, l, m, ag, ah;
int *e = &d;
short f, g;
unsigned j;
long n;
char aa[10];
static unsigned char o(void);
static int *p(int *);
static int y() {
  int q = 6, r = 0;
  int *s;
  short *t, *u = &t;
  l = p(&q);
  o();
  if (n) {
    int v = 0, w;
    int x[] = {&v, &r};
    b = *s;
    w = &u;
  }
}
unsigned char o() {
  int l_1339[3];
  int *ab = &l_1339[2];
  int k;
  m = 0;
  for (; m < 3; m++)
    l_1339[m] = 8;
  p(l_1339);
  for (; j <= 7; j++) {
    for (;; f--)
      if (*a)
        break;
    char *ac;
    char *ad[30];
    char *ae = ad;
    char *f = &ae;
    k = 0;
    for (; k < 3; k++)
      ad[k] = &ac;
    *ab = 0 != &g;
  }; //     optimize_me_not()
}
int *p(int *z) {
  long af = 5;
  for (; af < 30; af = af + 6)
    h = *z;
  int i = 0;
  for (; i < 10; i++)
    aa[i] = *a = *c ^ 2;
  *e = ag;
  return ah;
}
int main() { y(); }



$ cat cmds
b abc.c:45
r
p l_1339[2]
kill
q

Reply via email to