[CIR] Implement lifetime markers for stack allocations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
CIRGen currently does not emit `llvm.lifetime.start` / `llvm.lifetime.end`
intrinsics for stack-allocated locals and temporaries. This is tracked in
`clang/include/clang/CIR/MissingFeatures.h` as `emitLifetimeMarkers()`, and
guarded by `assert(!cir::MissingFeatures::emitLifetimeMarkers())` at four
call sites:
- `clang/lib/CIR/CodeGen/CIRGenCleanup.cpp` — `EHScopeStack::requiresCatchOrCleanup`
- `clang/lib/CIR/CodeGen/CIRGenCall.cpp` — call argument / SRet setup
- `clang/lib/CIR/CodeGen/CIRGenExpr.cpp` — `emitMaterializeTemporaryExpr`
- `clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp` — `withReturnValueSlot`
The auto-variable path (`EmitAutoVarAlloca` in classic CodeGen, see
`CGDecl.cpp:1614-1637`) also needs to be wired up on the CIR side.
Classic CodeGen reference: `CodeGenFunction::EmitLifetimeStart` /
`EmitLifetimeEnd` in `clang/lib/CodeGen/CGDecl.cpp`, gated by
`ShouldEmitLifetimeMarkers` (`CodeGenFunction.cpp:60`).
The cleanup-scope plumbing is already partially in place: `LifetimeMarker`
cleanup kind is defined in `clang/lib/CIR/CodeGen/EHScopeStack.h`, and
`EHCleanupScope::isLifetimeMarker()` is used by the cleanup dispatcher.
Contributor guide
Assessment
This issue has not been assessed yet.