<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70948>70948</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Call site info: Volatile registers shouldn't be used in DW_AT_call_target expressions
</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]`.
The DW_AT_call_target attribute on the call site info, below, is not only wrong but also we should not be using a volatile register in `DW_AT_call_target` expressions.
```
DW_AT_call_target (DW_OP_reg0 RAX)
```
>From the DWARF 5 spec
> The call site may have a DW_AT_call_target attribute which is a DWARF expression. For indirect calls or jumps where it is unknown at compile time which subprogram will be called the expression computes the address of the subprogram that will be called.
>
> The DWARF expression should not use register or memory locations that might be clobbered by the call.
`DW_AT_call_target_clobbered` should be used instead.
$ 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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVl2P4ygW_TXk5coRxnbsPOQhVensrtTabrVqt0bzEmGMbXoweADno3_9CJzvpHr6YVDJVWUu5557OFxDrRWN4nyBsheUrSZ0cK02iy-v_z7Qzk5KXR0WTFLVwJYbK7SCuJjiKQZEipKlcYkpIyVOyoIlOKvyZD6v8pywIq9Izti8SGKGyBzhFcLLN2oa7lCyhH0x28zSaFB_KL1TkRRq2EeNGsa48fkfBa7lYHhvdDUwbqDkUu8QefXvDUckt0AVCFUJw5kDRqUE1xo9NC2gGS7RDIegraOl5OA0bIVxA5VQD4o5Xw2a4S2a4Sm8tfwUR6vKcGtBWJCaVrwCoZz2od-WvwXMV6CqAmpPy32o52o506o64XDlzAF2HBruwjTTFfdLAtE_d9pU0DsDKHsxdA-IvECBspWnc62DZ7Z63yzfNn7dxgURgTpnRDk4DnrUKYBa4TgIVWvP8SyXsKC0A63kAXZGqwbKwQGVVnt2ttWDrEJEyWGwQjVAYasldUJ6_RthHTcggloPTHz5fN97xYRWdgrX3L1a40_497GMcSBSrN43X75uDG8weJVPlrkDGJ9ro7tQ8-p9-W0NGdies2NA8ils5UWNjh6gpVsO9Kcq7lrBWq8UPaJeaprCWptbm1nQBr4PXW9h570Iwvm1Rz8DdcB013v5nOhO4HYoe6MbQzvYCSm92h6LV6GWS76wdnB89NTJjboeLXYBcS11d0jTiwq3etzXdL3rg73aZW2g4502B5CaUX9G7JioE00bHMKkLktueAXl4ey86d2uP0i9OS_zhjlmD34L58s6TqtbkPFJUmDUgePWTVnfP3WFdWZgDl6o5YDyl_ElnA-7UA5-_ECkQGTu58FwNxgFe5S8AMpXp_jQAl9Ct0PJEiVLpYWSQnF_KLPVM9jtI-op0x24j_YJjwXkq_Pf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