<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 - Confusing backtrace at -O2"
   href="https://bugs.llvm.org/show_bug.cgi?id=46010">46010</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Confusing backtrace at -O2
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>qrzhang@gatech.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When stopped at line 4, the backtrack should be main->b. With "-O2", it gives
main->d->b. See the following example. At "-O2", only breakpoint 1.3 was hit.


$ clang-trunk -v
clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
58684fbb6f2e6871f3f96ac8c7166a7d7486e971)



#expected backtrace
$ clang-trunk -g abc.c
$ lldb-trunk -s cmds -b a.out
(lldb) b 4
Breakpoint 1: where = a.out`b + 18 at abc.c:4:4, address = 0x0000000000400492
(lldb) r
Process 1631 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x0000000000400492 a.out`b at abc.c:4:4
   1    int a;
   2    void b() {
   3      int *c = &a;
-> 4      *c = 0; // stop here
   5    }
   6    void d() { b(); }
   7    int main() {

Process 1631 launched: '/home/absozero/projects/LLDB-testing/reduce/a.out'
(x86_64)
(lldb) bt
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
  * frame #0: 0x0000000000400492 a.out`b at abc.c:4:4
    frame #1: 0x00000000004004b9 a.out`main at abc.c:8:3
    frame #2: 0x00007ffff7a05b97 libc.so.6`__libc_start_main + 231
    frame #3: 0x00000000004003ba a.out`_start + 42
(lldb) kill



#backtrace at -O2
$ clang-trunk -g abc.c -O2
$ lldb-trunk -s cmds -b a.out
(lldb) b 4
Breakpoint 1: 3 locations.
(lldb) r
Process 17759 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.3
    frame #0: 0x00000000004004a0 a.out`main [inlined] b at abc.c:4:6
   1    int a;
   2    void b() {
   3      int *c = &a;
-> 4      *c = 0; // stop here
   5    }
   6    void d() { b(); }
   7    int main() {

Process 17759 launched: '/home/absozero/projects/LLDB-testing/reduce/a.out'
(x86_64)
(lldb) bt
* thread #1, name = 'a.out', stop reason = breakpoint 1.3
  * frame #0: 0x00000000004004a0 a.out`main [inlined] b at abc.c:4:6
    frame #1: 0x00000000004004a0 a.out`main [inlined] d at abc.c:6
    frame #2: 0x00000000004004a0 a.out`main at abc.c:9
    frame #3: 0x00007ffff7a05b97 libc.so.6`__libc_start_main + 231
    frame #4: 0x00000000004003ba a.out`_start + 42
(lldb) kill


$ cat abc.c
int a;
void b() {
  int *c = &a;
  *c = 0; // stop here
}
void d() { b(); }
int main() {
  b();
  d();
}

$ cat cmds
b 4
r
bt
kill
q</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>