https://bugs.llvm.org/show_bug.cgi?id=41766

            Bug ID: 41766
           Summary: Clang-trunk Generates Wrong Debug values with -O1
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: wrong-debug
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedb...@nondot.org
          Reporter: yuanboli...@gmail.com
                CC: dav...@freebsd.org, jdevliegh...@apple.com,
                    keith.wal...@arm.com, llvm-bugs@lists.llvm.org,
                    paul_robin...@playstation.sony.com

$ clang-trunk --version
clang version 9.0.0 (trunk 355785)
Target: x86_64-unknown-linux-gnu
Thread model: posix


$ lldb-trunk --version
lldb version 9.0.0 (https://llvm.org/svn/llvm-project/lldb/trunk revision
355785)
  clang revision 355785
  llvm revision 355785


$ cat abc.c
int c = 2, e;
short d;
char(a)(b) {}
int main() {
  int p_99;
  short f = p_99 = 0 <= 7;
  for (; d < 9;) {
    optimize_me_not();
    {
      int g;
      if (c)
        break;
      f &&a(p_99 ^= 1);
    }
    if (p_99)
      e = 0;
  }
}


$ cat outer.c 
optimize_me_not() {}


$ cat cmds
b 8
r
p p_99
kill
q


$ clang-trunk abc.c outer.c -O0 -g


$ lldb-trunk -s cmds -b a.out 
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/ybli/Projects/LLDB-testing/reduce.llvm/cmds'.
(lldb) b 8
Breakpoint 1: where = a.out`main + 45 at abc.c:8:5, address =
0x00000000004004bd
(lldb) r
Process 21953 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004bd a.out`main at abc.c:8:5
   5      int p_99;
   6      short f = p_99 = 0 <= 7;
   7      for (; d < 9;) {
-> 8        optimize_me_not();
   9        {
   10         int g;
   11         if (c)

Process 21953 launched: '/home/ybli/Projects/LLDB-testing/reduce.llvm/a.out'
(x86_64)
(lldb) p p_99
(int) $0 = 1
(lldb) kill
Process 21953 exited with status = 9 (0x00000009) 
(lldb) q


$ clang-trunk abc.c outer.c -O1 -g


$ lldb-trunk -s cmds -b a.out 
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/ybli/Projects/LLDB-testing/reduce.llvm/cmds'.
(lldb) b 8
Breakpoint 1: where = a.out`main + 16 at abc.c:8:5, address =
0x00000000004004a0
(lldb) r
Process 27481 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004a0 a.out`main at abc.c:8:5
   5      int p_99;
   6      short f = p_99 = 0 <= 7;
   7      for (; d < 9;) {
-> 8        optimize_me_not();
   9        {
   10         int g;
   11         if (c)

Process 27481 launched: '/home/ybli/Projects/LLDB-testing/reduce.llvm/a.out'
(x86_64)
(lldb) p p_99
(int) $0 = 0
(lldb) kill
Process 27481 exited with status = 9 (0x00000009) 
(lldb) q


It is worth noting that if we remove the unnecessary '{' and '}' immediate
after "optimize_me_not()" in abc.c, the bug cannot reproduce.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to