https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95835
Bug ID: 95835
Summary: Wrong line information at Og
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: massarelli at diag dot uniroma1.it
Target Milestone: ---
Line information is wrong at line 6.
Line 6 should not be hit as it is the declaration of variables.
>From the disassembly, it seems that the program is actually executing line 5.
$ cat a.c
int a ;
int main () {
for (;
a < 2;
a++) {
int i, j, k;
}
}
$ cat -n a.c
1 int a ;
2 int main () {
3 for (;
4 a < 2;
5 a++) {
6 int i, j, k;
7 }
8 }
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/tmp/gcc_build --disable-multilib
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20200619 (experimental) (GCC)
$ gdb -v
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
$ gcc -Og -g -o opt a.c
$ gdb opt
(gdb) b main
Breakpoint 1 at 0x400486: file a.c, line 3.
(gdb) r
Starting program: opt
Breakpoint 1, main () at aaa.c:3
3 for (;
(gdb) s
4 a < 2;
(gdb) s
6 int i, j, k;
(gdb) disassemble
Dump of assembler code for function main:
0x0000000000400486 <+0>: jmp 0x400491 <main+11>
=> 0x0000000000400488 <+2>: add $0x1,%eax
0x000000000040048b <+5>: mov %eax,0x200b9b(%rip) # 0x60102c
<a>
0x0000000000400491 <+11>: mov 0x200b95(%rip),%eax # 0x60102c
<a>
0x0000000000400497 <+17>: cmp $0x1,%eax
0x000000000040049a <+20>: jle 0x400488 <main+2>
0x000000000040049c <+22>: mov $0x0,%eax
0x00000000004004a1 <+27>: retq
End of assembler dump.
(gdb)