<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 - Incorrect call frame info on X86_64 target"
   href="https://bugs.llvm.org/show_bug.cgi?id=50327">50327</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect call frame info on X86_64 target
          </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>djordje.todorovic@syrmia.com
          </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>$ cat test.c
#include <stdlib.h>

int f2(char *input) { return crasher(input, 1); }
int crasher(char *input, int crash) {
  if (crash)
    input = NULL;
  input[0] = '1';
  input[1] = '2';
  input[2] = '3';
  input[3] = '\0';
  f2(input);
  if (crash)
    return 0;
  else
    return 1;
}

int f1() {
  char *input = (char *)malloc(sizeof(char) * 10);
  return crasher(input, 0);
}
int main(int argc, char **argv) {
  f1();
  return 0;
}

This small example when compiled with -O1 produces call frame info that causes
incorrect backtrace in GDB.

$ clang -O1 test.c -o test
$ ./test
Segmentation fault (core dumped)
$ lldb test -c core.test
...
(lldb) bt
* thread #1, name = 'test', stop reason = signal SIGSEGV
  * frame #0: 0x0000000000401156 test`f2 + 6
    frame #1: 0x000000000040116c test`crasher + 12
    frame #2: 0x000000000040115b test`f2 + 11
    frame #3: 0x000000000040116c test`crasher + 12
    frame #4: 0x000000000040115b test`f2 + 11
    frame #5: 0x000000000040116c test`crasher + 12
    frame #6: 0x000000000040115b test`f2 + 11
    frame #7: 0x000000000040116c test`crasher + 12
    frame #8: 0x000000000040115b test`f2 + 11
    frame #9: 0x000000000040116c test`crasher + 12
    frame #10: 0x000000000040115b test`f2 + 11
    frame #11: 0x000000000040116c test`crasher + 12
    frame #12: 0x000000000040115b test`f2 + 11
    frame #13: 0x000000000040116c test`crasher + 12
...

With gcc, it looks ok:
$ gcc -O1 test.c -o test-gcc
$ ./test-gcc
Segmentation fault (core dumped)
$ lldb ./test-gcc -c core.test-gcc
...
(lldb) bt
* thread #1, name = 'test-gcc', stop reason = signal SIGSEGV
  * frame #0: 0x000000000040115b test-gcc`crasher + 14
    frame #1: 0x000000000040118c test-gcc`f2 + 19
    frame #2: 0x000000000040116f test-gcc`crasher + 34
    frame #3: 0x00000000004011ac test-gcc`f1 + 27
    frame #4: 0x00000000004011bf test-gcc`main + 14
    frame #5: 0x00007fea1df1c555 libc.so.6`__libc_start_main + 245
    frame #6: 0x0000000000401089 test-gcc`_start + 41


This has been reproduced with x86_64 GNU/Linux platform.</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>