<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 DWARF expressions produced with SafeStack"
   href="https://bugs.llvm.org/show_bug.cgi?id=44585">44585</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect DWARF expressions produced with SafeStack
          </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>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>DebugInfo
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>leonardchan@google.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>Given the following snippet:

```
#include <stdio.h>
#include <string>

int main(int argc, char* argv[]) {
  std::string value = "asdf";
  printf("%s\n", value.c_str());
  return 0;
}
```

And compiling with (tip of tree) clang: `clang++ -g -fsanitize=safe-stack
/tmp/test.cpp`, we are unable to identify symbols:

```
$ gdb a.out
(gdb) start
5           int main(int argc, char* argv[]) {
(gdb) n
6             std::string value = "asdf";
(gdb) 
7             printf("%s\n", value.c_str());
(gdb) p value
Cannot access memory at address 0x1
```

We can assert `p value` prints "asdf" when compiling without SafeStack. A
dwarfdump shows that "value" looks like:

```
0x00001ab0:     DW_TAG_variable
                  DW_AT_location        (0x00000000: 
                     [0x0000000000000013, 0x000000000000003a): DW_OP_breg2
RCX-32
                     [0x000000000000003a, 0x0000000000000128): DW_OP_breg6
RBP-40, DW_OP_constu 0x20, DW_OP_minus, DW_OP_deref)
                  DW_AT_name    ("value")
                  DW_AT_decl_file       ("/tmp/test.cpp")
                  DW_AT_decl_line       (5)
                  DW_AT_type    (0x00000741 "string")
```

The `DW_OP_breg2 RCX-32` seems correct, but the `DW_OP_breg6 RBP-40,
DW_OP_constu 0x20, DW_OP_minus, DW_OP_deref` should be something like
`DW_OP_breg6 RBP-40, DW_OP_deref, DW_OP_constu 0x20, DW_OP_minus` to reflect:

```
movq    -40(%rbp), %rax
addq    $-40, %rax
```

A bisect was able to determine that <a href="https://reviews.llvm.org/D68945">https://reviews.llvm.org/D68945</a> introduced
this bug. The issue was initially addressed in <a href="https://reviews.llvm.org/D65172">https://reviews.llvm.org/D65172</a>
but was re-introduced.</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>