<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/70949>70949</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            all site info: Register offsets ignored when emitting DW_AT_call_target
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          OCHyams
      </td>
    </tr>
</table>

<pre>
    clang version 18.0.0 (bc41b0ac2b03b8c305d7399d772c87d27cc9831c)
Target: x86_64-unknown-linux-gnu

In the reproducer below, there's an indirect call through `b`'s vtable to virtual function `v`. The vtable address is loaded into `RAX`, and as `v` is the second vtable entry we get the code `call qword ptr [rax + 8]`.

Despite this, clang emits a call site entry with DW_AT_call_target expression `DW_OP_reg0`. In this instance the expression should be `DW_OP_breg0+8`.

```
DW_AT_call_target (DW_OP_reg0 RAX)
```

$ cat test.cpp
```
struct Base {
 virtual int zz() { return x; }
  [[clang::noinline]]
  virtual int v() { return zz(); }
  int x;
};
struct Child: public Base {
 [[clang::noinline]]
  virtual int v() { return x * 2; }
  int x;
};

[[clang::noinline]]
[[clang::disable_tail_calls]]
int foo(Base* b) {
  return b->v();
}
```

$ clang test.cpp -O2 -g -c -o test.o
$ llvm-dwarfdump test.o --name foo --show-children
```
0x00000027: DW_TAG_subprogram
 DW_AT_name ("foo")
              ...


0x00000037: DW_TAG_formal_parameter
                ...

0x00000040: DW_TAG_call_site
                DW_AT_call_target    (DW_OP_reg0 RAX)
 DW_AT_call_return_pc (0x0000000000000007)

0x00000044: DW_TAG_call_site_parameter
                  ...

0x0000004b: NULL

0x0000004c:   NULL
```


$ llvm-objdump --disassemble-symbols=_Z3fooP4Base test.o --x86-asm-syntax=intel
```
0000000000000000 <_Z3fooP4Base>:
 0: 50                           push rax
       1: 48 8b 07 mov  rax, qword ptr [rdi]
       4: ff 50 08                     call qword ptr [rax + 0x8]
       7: 59                           pop  rcx
 8: c3                           ret
```

N.B. DW_AT_call_target should not be used if there are volatile registers involved, see 
#70948.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt1u27gSfhr6ZiCDJmVLuvCFHTfnHKBoiyIHXeyNQVFjiV2a1JKU7fTpF6R_4sRu2oslAsXg_H0z8w1J4b1qDeKcTJdkuhqJIXTWzT8__PdZbP2ots3zXGphWtih88oamJRjOqZAWFnLfFJTIVlNeV1KTqdNwauqKQomy6JhhZRVySeSsIrQFaGLJ-FaDIQv4FDO1rM8G8xfxu5NppUZDllrhqPe8fs_A6FDcNg72wwSHdSo7Z6wh7jvkLDCgzCgTKMcygBSaA2hc3ZoOyAzWpMZTUq7IGqNECzslAuD0LAZjAwxGzKjOzKjY3jq8Kwnmsah96A8aCsabECZYKPq18UfyecDCNOA8GfzqBqxepTWNGc_aIJ7hj1CiyGJpW0wmiSgf--ta6APDsh06cQBCFtCSaarCOe6Div0vQoIoVM-hj62A7cqeBDHpH2Un8Kp0MHq23rxtI6idUg1Bzz0MadTyqtv689f1g5bmnJPlVYelPFBGIkJ7JWF7-ygG6jxxbZOxmxZvkUb63P8O4K_QUJY-RIeYkXP9HhjevqyHKQIENCHsez7u6o-uEEGWAqPQIrlcfPSbGUC_PhBWElYFcXgMAzOwIHwJZBidVKHNALLVF7CF4QvjFVGK4OxKdOL2rXb3a3Xc6Q3zqN2DHjCX6wuv0_gHzqlmzgb_VBrJd8m8--AiyxbAPttbKfv78S-UWqUj2OwDkLpxAB_rR5jbqwlrIyJRlT1CesZ1QlynRH-YXep6QvGX3AmTcmZNZB9ZpC1kEnI7HHXvuhqvdtmzV64TTNs-5MYssyILUaQkGW-s_tMxhY5NHdD0wNNixWxiatv66fFf9Z-qHtnWye2p6yO85Acp5RYqgG7zAC8WuPx69l6FYhfB9pYtxV63QsnthjQ3fN24-_sKadXntKsxgPlvovbgQZ4Z6av9Y8NXfcy6p9jX1bxcg68BpffA_erTH-eax3d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