[CIR] Upstream thread local storage support
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Overview
Upstream code from the incubator project to replace errorNYI calls in the upstream
CIR implementation related to thread local storage, including TLS global variable
lvalue emission, TLS static local variable creation, and registering destructors
for temporaries with static or thread storage duration.
Upstream NYI locations:
- `CIRGenExpr.cpp` — `emitGlobalVarDeclLValue`: emitting lvalues for
`thread_local` variables with dynamic TLS (`TLS_Dynamic`) via
`getCXXABI().emitThreadLocalVarDeclLValue()`
- `CIRGenDecl.cpp` — `getOrCreateStaticVarDecl`: calling `setTLSMode()` on
static local variables that have a TLS kind
- `CIRGenExpr.cpp` — `pushTemporaryCleanup`: registering global destructors for
temporaries with static or thread storage duration that require destruction
### Suggested minimal test case
```cpp
thread_local int tls_var = 42;
int get_tls() {
return tls_var;
}
thread_local int tls_init = get_tls();
void use_static_tls() {
static thread_local int local_tls = 0;
local_tls++;
}
```
### Existing incubator tests
- `clang/test/CIR/CodeGen/thread-local.cpp`
- `clang/test/CIR/CodeGen/tls.c`
Contributor guide
Assessment
This issue has not been assessed yet.