<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Wrong debug info generated at -O1 (-O0/O2/O3 are correct)"
   href="https://bugs.llvm.org/show_bug.cgi?id=46007">46007</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong debug info generated at -O1 (-O0/O2/O3 are correct)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yangyibiao@hust.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>