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

            Bug ID: 96002
           Summary: Wrong argument value shown by gdb at Og
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-debug
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: massarelli at diag dot uniroma1.it
  Target Milestone: ---
          Keywords: wrong-debug

The second time line 5 is hit arguments p_21 is assigned a wrong value.

$ cat -n a.c
     1  int a, c;
     2  int *b[3];
     3  void d(int e, short f, int g, char p_21) {
     4    int h;
     5    for (; c < 3; c++)
     6      b[c] = &h;
     7  }
     8  int main() { d(a, 0, 1, 0); }

$ cat a.c
int a, c;
int *b[3];
void d(int e, short f, int g, char p_21) {
  int h;
  for (; c < 3; c++)
    b[c] = &h;
}
int main() { d(a, 0, 1, 0); }

$ 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 20200624 (experimental) (GCC) 

$ gcc -Og -g -o opt a.c

$ gdb opt
Reading symbols from opt...
(gdb) b main
Breakpoint 1 at 0x4004ad: file a.c, line 8.
(gdb) r
Starting program: opt 
Breakpoint 1, main () at a.c:8
8       int main() { d(a, 0, 1, 0); }
(gdb) s
d (e=0, f=f@entry=0, g=g@entry=1, p_21=p_21@entry=0 '\000') at a.c:5
5         for (; c < 3; c++)
(gdb) s
6           b[c] = &h;
(gdb) bt
#0  d (e=0, f=f@entry=0, g=g@entry=1, p_21=p_21@entry=0 '\000') at a.c:6
#1  0x00000000004004c7 in main () at a.c:8
(gdb) s
5         for (; c < 3; c++)
(gdb) bt
#0  d (e=0, f=f@entry=0, g=g@entry=1, p_21=124 '|', p_21@entry=0 '\000') at
a.c:5
#1  0x00000000004004c7 in main () at a.c:8
(gdb)

Reply via email to