llvm / llvm/llvm-project

[CIR] Upstream thread local storage support

Open
#192,308 1 comment 0 reactions 1 assignee Claimed by @erichkeane View on GitHub
ClangIR
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.