Skip to content

Incorrect debug info generated at -O3 (-O0 is correct) #68898

Open
@hemangdash

Description

$ clang-trunk --version
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 1964118ace4926f4d103aa0538db1f1f5baa343a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ cat abc.c
int a[256];
int b, c;
char d;
int main() {
  int e = 0;
  for (; e < 256; e++)
    a[e] = e;
  short f;
  char l_1029 = 9;
  int *g = &c;
  d++;
  f = -1;
  l_1029 = f ^ 52;
  *g = *g != 0;
  b = 5;
}
$ clang-trunk abc.c -g -O0
$ lldb-trunk ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '/data2/hemang/test3/reduction/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/data2/hemang/test3/reduction/cmds'.
(lldb) b 14
Breakpoint 1: where = a.out`main + 107 at abc.c:14:9, address = 0x000000000000119b
(lldb) r
Process 539940 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x000055555555519b a.out`main at abc.c:14:9
   11  	  d++;
   12  	  f = -1;
   13  	  l_1029 = f ^ 52;
-> 14  	  *g = *g != 0;
   15  	  b = 5;
   16  	}
Process 539940 launched: '/data2/hemang/test3/reduction/a.out' (x86_64)
(lldb) p l_1029
(char) '\xcb'
(lldb) kill
Process 539940 exited with status = 9 (0x00000009) killed
(lldb) q
$ clang-trunk abc.c -g -O3
$ lldb-trunk ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '/data2/hemang/test3/reduction/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/data2/hemang/test3/reduction/cmds'.
(lldb) b 14
Breakpoint 1: where = a.out`main + 902 at abc.c:14:11, address = 0x00000000000014b6
(lldb) r
Process 541323 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00005555555554b6 a.out`main at abc.c:14:11
   11  	  d++;
   12  	  f = -1;
   13  	  l_1029 = f ^ 52;
-> 14  	  *g = *g != 0;
   15  	  b = 5;
   16  	}
Process 541323 launched: '/data2/hemang/test3/reduction/a.out' (x86_64)
(lldb) p l_1029
(char) '\t'
(lldb) kill
Process 541323 exited with status = 9 (0x00000009) killed
(lldb) q
$ cat cmds
b 14
r
p l_1029
kill
q

The issue exists as early as clang-3.4.

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorconfirmedVerified by a second partydebuginfollvm:optimizations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions