<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58184>58184</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++] Clang-15 vs Clang-14 local static init guards
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
eskimo-software
</td>
</tr>
</table>
<pre>
I'm using Clang++ to compile for a Cortex-M0+ target, and in moving from version 14 to version 15 I've found a difference in the code generated for guard variables for local statics.
So, for example:
```
int main()
{
static knl::QueueN<uint32_t, 8> valQueue;
...
}
```
Clang-14 generates the following:
```
ldr r0, .LCPI0_4
ldrb r0, [r0]
dmb sy
lsls r0, r0, #31
beq .LBB0_8
```
Clang-15 now generates:
```
ldr r0, .LCPI0_4
movs r1, #2
bl __atomic_load_1
lsls r0, r0, #31
beq .LBB0_8
```
An important consequence of this is that the second case actually requires an implementation of __atomic_load_1 to be provided from somewhere external to the compiler (e.g. -latomic?), whereas the first doesn't.
Note that the source code doesn't explicitly use atomics, only the implied usage by the statics (which can of course be disabled with `-fno-threadsafe-statics`).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVNuO2zgM_Rr7hYhhy3EuD36YpDtAgbbYoh8QyBJtaytLqSQnnb9fSvZkBovdBQrUMHwRycND6lCdlS_tx4ztJ5i9MgOcNTdDxk50Q7Ag7HRVGqG3DjicrQv4c_O5TFbuBgwZOwM3EpSByd4iQu_sBDd0XlkD1TaiPP4aiLluEW-mIA5S9T06NAIjQhiRMkqEAQ06HlCmxMPMnYQbd4p3Gn1a01ZwDT7woIQvsvJDVj4tz282coo--JNPV41ZvVqyXbne6VeZABNXJmOHjB1Xl_1p-QC6FnT4bnSEqJ--zjjjl6w-zxRas0sq_pDVfxA3nYxZ_S68KF557T_8K4HU6w216LVcnzrQW63tnVr5X8S1dODKmLz4dP7zY3nZPta7mHixZc2JPpo1tZw68C-rn9f-zW_1ZnVdLeYOfxDw6VReDv9HuwFj72_Uf5UsqWUhUa3p2ZpdA1wuPNhJiYu2XF6q38J6eT4ZUNOVZMxp84U1Hn_MSX22p94rDyruAQ9pIzyShwTBPQIXYeZav4CjCOVoq3iC0jihiToheRPGP5hH8XcIV0ejIaOa42x4O-F9JNWTQAM6Qzomt0X7adoc1XXAYihgoxe4rH6OEqWKUyBfhaKcDyAtetLwPhQA70v9YgO-q8XOTqzT9YggAlethApU1xyLTMl8zGMNrcXAWKMi6rPnA0K3LK5zF3neRyVG6lEqX1AWwqGSpfJxWCXcVRiBdmHTG7sJI5GXnve4WSHi_rDjOig5ttVu15TNrqy2uWxreayPPA9EEFvSs3g7nEjY8BAiKekxS-8PBjpTVFiOD5_PTrdjCNekVEb9fB6I2twV1HX60fr2-trQfv2Fgsb7WXk_k7bZc3OoDtt8bDt2xB6bHfb9sRNluRM1q7BvmrqSclexXPMOtY9sM8YM3iFB0DcxzlXLSsYqCquqmq6irPYRC7f9viuZaLJtiXQm6SLyKKwbctcmSt08eDJq5YN_M3Lv1WAwNSfi8zmM1rXov6vJbrztw507zBOFNpXwN4UV0xo">