<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69167>69167</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
C23 mode doesn't compile thread local declarations properly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gustedt
</td>
</tr>
</table>
<pre>
In C23, the keywords `_Thread_local` and `thread_local` are synonyms. But with clang 17 the following code does not compile
```
extern thread_local unsigned a;
_Thread_local unsigned a = 0;
```
This is because clang seems to use different tls models for the two declarations. (gcc has no problem and uses static initialization for both.)
Obviously nobody would write such code with two different specifications consciously, but I stumbled into this because I had `extern` declaration and definition in different files, both using `thread_local`. One of them included `threads.h` and the other one didn't. So one got replaced by the C17 macro definition in that header to `_Thread_local`.
Generally I think that dynamic initialization for thread local storage should not be used in C mode, in particular not in C23 mode. C never needs dynamic initialization.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VM2O2zYQfhr6MoggUf7TQYesFy72lENzDyhyJLKhSIMzWtd9-oLUbqpsE8CQYXo08_1xFJGbAmIvDk_i8LxTC9uY-mkhRsO7IZpH_xLgIlshL8AW4Ts-7jEZAnGsv321CZX55qNWXhxrUMHkc_54nBDoEWJ4zFTB08Jwd2xBexUmaE6l7xi9j3cXJtDRIJiIBCEy6DjfnEdRP4v689vzWL99yk_8mzEF2A6FJRReBpRon9ayn8BuCkC0z1D_KPvQfH1-tY7AEQyo1UL4hpwQZwKOkI-MG0dMGBjYE8zRoCcYYyrk-B7BoPYqKXYxUAVCnietwarMEm4pDh7not9CSECs2GlwwbFT3v1TXivthsi2ErLbwvsyvLq4kH9AiNkyuMfFG7gnxwi0aLtqWkQvUH5gpRtqNzq9wgIdA-m1VfZ7WBhegHiZB48GXOAIbDc6vIBVxfHVg-z1hmahY3AsLGIAFzaTR-eRypDIFhbKzv8_OhV8CQhxzCrO4IL2i8FNxqiy77nLOke2mCCGbIcJQp64gj9jOZgiQ8KbVxoNDI9SfmlOMCud4geUbBWDRWUwZXt_kfQKtvr_gQGT8v4BL1mf8H3tYB5Bzb92cUUPaxaJY1ITAtliW079gDkHWXK4lDBlpVyAm0rs9OJVKmWuXM1SUAFcIOArJgiIhn4zvVoR70zfmq7t1A775tid9vvDuTvtbC-H43k8tYema3Xb4fnc1epkjk0t5dDh2O5cL2vZNnVzrM_7_eFU7Q9N142H_YiHYdw3ndjXOCvnK-9f5yqmaeeIFuyPXXM87bwa0FNZN1IGvEP5U0iZt0_q8zufhmUisa-9I6b_urBjj_073bIgisPvG-JnTbe3LV-vGyb_2C3J95b5RqL9LORVyOvk2C5DpeMs5DXPevv6dEvxL9Qs5LUgJCGvhcG_AQAA__8_P78L">