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

            Bug ID: 89463
           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 bug affects the latest trunk.
It also affects gcc-8 and gcc-7.
gcc-6 works fine.

With "-O3", it incorrectly prints "i=0".



$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.1 20190222 (experimental) [trunk revision 269113] (GCC)



$ cat abc.c
int a;
int main() {
  int i;
  for (; a < 10; a++)
    i = 0;
  for (; i < 6; i++)
    ;
  optimize_me_not();
}

$ cat outer.c
optimize_me_not() {}


$ cat cmds
b 8
r
p i
kill
q



$ gcc-trunk -g abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4004b9: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8         optimize_me_not();
$1 = 6
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 29883) killed]






$ gcc-trunk -g abc.c outer.c -O3
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4003b7: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8         optimize_me_not();
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 31868) killed]

Reply via email to