<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116514>116514</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang uses global register variables as scratch registers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
brandtbucher
</td>
</tr>
</table>
<pre>
Example: https://godbolt.org/z/h8P39fYE9
The linked snippet declares a global register variable `rbp`, mapped to the register of the same name. I would expect that this register would not be used in the current compilation unit unless the variable is explicitly assigned to. However, Clang seems to use it as a scratch register anyways.
For context, I'm working on CPython's experimental JIT. We use Clang to compile snippets of machine code ahead-of-time to form templates for the JIT. We'd like to enable frame pointers for JIT code, but to manage them ourselves, rather than having them be repeatedly pushed and popped in each template. Since no `-ffixed-rbp` option exists, I was expecting that declaring `rbp` as a global register variable would ensure it's not touched in the machine code. That doesn't seem to be the case.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE2P2zYQ_TX0ZWBBomzLPuiw3cSocwrQBYoeR-LIYpciBc7IH_31BWlnNwiQiwSC8_HmvcdBZnv2RK3a_qG2X1a4yBhi20X0RrqlHymuumDu7dcbTrMjVb_AKDKzql-UPip9PAfTBSdFiGelj_8pfRz33-vD8M_Xgyq_qPLl8X0bCZz172SAvZ1nEjDUO4zEgHB2oUMHkc6WhSJcMFrsHIHalbGb1a5U-hUmnGcyIAFkpM_gMOQz40TgcaICTnANizNAt5l6ARkxfSx_5jzufRDoCBYmA9bnKv0SI3mBPkyzdSg2eFi8FVi8I-Yc84HOcmrhbG_F3eHJZQJYwJ_hSheKCfarQ38GJpo4YV-YwApgmpv7iNKPn7jQ36945-Jn6o4hQh-80E1SuZPSzQTXEN-tP0Pw8Pr9LmPwSjcZDkU7kRd08O30VsDfeb4nCAnPweiHCpzom7AfrSfogyHAkdCsw7AWO1HKGEKcQGiaHQpxOmYWntWVbgw4-55DyWdehpi0mIP1QvGR8e30lsunCbpFUvCEHs-Uak0QlsjkLsTpPqKMlJqghxEvacwc1CXRZ0Ih4-4wLzySAfQG5pCNYT0Q9uMH1gL-sr4n8CH5aD0M9kZm_fAThDlrSzfLkrue4Ir8tMyjJf7waDp-OPGh3G8d-3Se5yUmnbMqyWcS0mv68NnPlBfwlnsF4qSiZK8khjp6eBKZipVpa3OoD7iitmrqal_qbVWvxraihjqqzaYqzc7UujO6xGbo9ND0et9sV7bVpd5UVdWUZbWt6gLLqtlvDrjbD6buqVGbkia0rnDuMqWHvLLMC7VVtdtWm5XDjhznDaF1n3yktE7LIrYpYd0tZ1ab0iUiP0uIFUftw3YLE_-WMU6E_voQeLVE1_6yaayMS1f0YVL6mPo8f-s5hn-pF6WPGTcrfXxCv7T6_wAAAP__FS6s4w">