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

            Bug ID: 89801
           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 affects gcc-6 to gcc-trunk. gcc-5 works fine.

Bisect points to r222305.


$ gcc-trunk -v
gcc version 9.0.1 20190322 (experimental) [trunk revision 269869] (GCC)

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


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

Breakpoint 1, d () at abc.c:9
9         c = 3;
$1 = 1


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

Breakpoint 1, main () at abc.c:18
18        for (; i < 5; i++)
$1 = 0





$ cat abc.c
long a, b;
static int c, f;
static long d() {
  int *e = &c;
  int i = 0;
  for (; i < 1; i++)
    ;
  *e ^= b;
  c = 3;
  for (; 0;)
    optimize_me_not();
  ;
}
int main() {
  int i;
  d();
  i = 0;
  for (; i < 5; i++)
    for (; f; f++)
      ;
  a = c;
}


$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 9
r
p i
kill
q

Reply via email to