[llvm-bugs] [Bug 46007] New: Wrong debug info generated at -O1 (-O0/O2/O3 are correct)

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 20 08:40:48 PDT 2020


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

            Bug ID: 46007
           Summary: Wrong debug info generated at -O1 (-O0/O2/O3 are
                    correct)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at hust.edu.cn
                CC: jdevlieghere at apple.com, keith.walker at arm.com,
                    llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com

The expected output from lldb should be 1, but lldb outputs -8434 when the
program is compiled with "-O1". It behaves correctly when the program is
compiled with "-O0", "-O2", and "-O3".



$ cat small.c
void foo(char *x) {
  *x = 1;
}

int main(int argc, char **argv) {
  char c[10];
  foo(c);
  return 0;
}

$ cat cmds
b 8
r
p argc


$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ lldb --version
lldb version 11.0.0
  clang revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af
  llvm revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af


$ clang -g -O1 small.c; lldb -s cmds -b a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/yibiao/Debugger/cmds'.
(lldb) b 8
Breakpoint 1: where = a.out`main + 14 at small.c:8:3, address =
0x000000000040112e
(lldb) r
Process 8665 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x000000000040112e a.out`main(argc=-8434,
argv=0x00007fffffffe008) at small.c:8:3
   5    int main(int argc, char **argv) {
   6      char c[10];
   7      foo(c);
-> 8      return 0;
   9    }

Process 8665 launched: '/home/yibiao/Debugger/a.out' (x86_64)
(lldb) p argc
(int) $0 = -8434


/********************
When compiled with "-O0/O2/-O3", the value of argv is correct as follow.
*********************/ 

$ clang -g -O3 small.c; lldb -s cmds -b a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/yibiao/Debugger/cmds'.
(lldb) b 8
Breakpoint 1: where = a.out`main at small.c:8:3, address = 0x0000000000401120
(lldb) r
Process 8765 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x0000000000401120 a.out`main(argc=1, argv=0x00007fffffffe008) at
small.c:8:3
   5    int main(int argc, char **argv) {
   6      char c[10];
   7      foo(c);
-> 8      return 0;
   9    }

Process 8765 launched: '/home/yibiao/Debugger/a.out' (x86_64)
(lldb) p argc
(int) $0 = 1

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200520/04ad71d3/attachment-0001.html>


More information about the llvm-bugs mailing list