<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64390>64390</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang adds incorrect frame base information.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
billionai
</td>
</tr>
</table>
<pre>
The following code:
```
int main() {
return 0;
}
```
when compiled with `clang -O0 -g3` gives the following debug information and assembly:
```
00000058 000000000000001c 0000005c FDE cie=00000000 pc=0000000000001130..000000000000113f
DW_CFA_advance_loc: 1 to 0000000000001131
DW_CFA_def_cfa_offset: 16
DW_CFA_offset: r6 (rbp) at cfa-16
DW_CFA_advance_loc: 3 to 0000000000001134
DW_CFA_def_cfa_register: r6 (rbp)
DW_CFA_advance_loc: 10 to 000000000000113e
DW_CFA_def_cfa: r7 (rsp) ofs 8
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
<1><23>: Abbrev Number: 2 (DW_TAG_subprogram)
<24> DW_AT_low_pc : (addr_index: 0x0): 1130
<25> DW_AT_high_pc : 0xf
<29> DW_AT_frame_base : 1 byte block: 56 (DW_OP_reg6 (rbp))
<2b> DW_AT_name : (indexed string: 0x3): main
<2c> DW_AT_decl_file : 0
<2d> DW_AT_decl_line : 1
<2e> DW_AT_type : <0x32>
<32> DW_AT_external : 1
0000000000001130 <main>:
1130: 55 push %rbp
1131: 48 89 e5 mov %rsp,%rbp
1134: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
113b: 31 c0 xor %eax,%eax
113d: 5d pop %rbp
113e: c3 ret
```
As you can see, the CFA information regarding frame bases is completely correct and perfectly usable, but the DIE for the main function says that the frame information should be obtained from rbp.
This is a problem because when you set a watchpoint (at least in GDB with software watchpoints), when we reach instruction 113e, the difference in rbp makes it look like the variable was changed, because there's no way for the debugger to know that the frame base is no longer valid, and we get a spurious warning of a value change. GCC handles it by making the frame base be `DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)` instead.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVs2O4rwSfRqzKTVyEv6yYMFAM7qbO3fR0iyRfyqJbzt2ZDsNvP0nO-kmMPSniRAQu86pOlW2y8x7VRvELVn-IMvDjPWhsW7LldbKGqZm3Mrr9q1BqKzW9qxMDcJKJMWO0AOhO7Ki4ye9KhOgZcqQfEPyEsj6xzAODkPvDFBSjCNkfXjKMHyfGzQgbNspjRLOKjRAVlRoZmp4-UXhpS7IikKtPtBDuAtPIu9rUKayrmVBWQPMSGDeY8v19bvAaXqWG6B3TybGgaWA4-EVhEJSHD5noROTt2SfFXQ-fxipxhwcfp_2x92JyQ9mBJ60FaTYQQbBwgMiGxGfEInVSVTsZKvKY0io1T3pbcatgOQbx7tYABZAVOzly_qbGIonMSy-icFhrXxA9-jr30XSJx7wuYdEvE7EPomwlYfNg62x3d-PjOOk2GekeCXFPi_S7w52nDv8gP_2LR8U5dHv4ffpbffz5HveOVs71t7kAUSafEGKV0iOdm8nbc-nTgAMk7vIwKR0J2UkXuIAvdDIEPOQFfSeaTllalTdfFINwOreuozWg23lWIsnzjwOthnwa0Dg2or3-L5cweczSPr1v1i7acUeVfEbu2EtfsEHTUkOSvDBKVMP4RWjrrTn77jEVJdEoU-V0jioureUf1hqZXD0m93b4tQ2XLv7GIs9vRR5LO0UlEa-QHgJ6AzTcO9gegrctnKEJ2lptdxYUxmL3eh7uYSnT9f7JmV_GfM9BWcRvNjApgT8A9zaDxhhcf3vn-AXN-diDYslVPGcun0GFp1YFmn17V_oZZFO5eXddh34-I2vyEBQuFg3xoDsMsQQ_0wxcpIA-U0CbAePCUj7_hZ98RzpMCTkpDZP-8TOw9X2IJgBj0jyfWoG--PurgE4rJmTsTmkTQNx03hQPnUYjQH1FYR1DkVIzaJDV6EI-gq9Z1wnXt6HxH34zytU1qX_cWlA1RuRvHh2jb2IDXaDp2kUvrG9l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