[CIR] Upstream missing support for l-value references
- 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
CIR codegen implementation related to emitting lvalue references to static
local variables and lambda captures via `BindingDecl`:
- Referencing static local variables via `getOrCreateStaticVarDecl()` +
`createGetGlobal()` when a `VarDecl` is not found in `localDeclMap`
- Emitting const local variables as globals (promoting constant-initialized
`const` locals to global storage with internal linkage) via
`emitStaticVarDecl()`
- Looking up structured binding declarations captured by lambdas in
`LambdaCaptureFields` and calling `emitCapturedFieldLValue`
Upstream NYI locations:
- `CIRGenExpr.cpp` — `emitDeclRefLValue`: static local variable not in
`localDeclMap`
- `CIRGenDecl.cpp` — `emitAutoVarAlloca`: const local variable with constant
initializer promoted to global
- `CIRGenExpr.cpp` — `emitDeclRefLValue`: `BindingDecl` with enclosing lambda
capture
### Suggested minimal test case
```cpp
int get_static() {
static int counter = 0;
return counter++;
}
void use_const_local() {
const int table[] = {1, 2, 3, 4, 5};
volatile int x = table[2];
}
void test_lambda_binding_capture() {
int arr[2] = {1, 2};
auto [a, b] = arr;
auto lambda = [a, b]() { return a + b; };
lambda();
}
```
### Existing incubator tests
- `clang/test/CIR/CodeGen/static-vars.cpp`
- `clang/test/CIR/CodeGen/static-vars.c`
- `clang/test/CIR/CodeGen/const-alloca.cpp`
- `clang/test/CIR/CodeGen/lambda.cpp`
- `clang/test/CIR/CodeGen/structural-binding.cpp`
Contributor guide
Research direction
Start by reading the three NYI locations in CIRGenExpr.cpp and CIRGenDecl.cpp, then run the listed CIR tests, especially static-vars.cpp, const-alloca.cpp, lambda.cpp, and structural-binding.cpp. Implement support for the three BindingDecl, static-local, and const-local cases described in the issue, and confirm the existing incubator tests pass without the relevant errorNYI paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100