llvm / llvm/llvm-project

[CIR] Implement lifetime markers for stack allocations

Open
#198,961 2 comments 0 reactions 1 assignee Claimed by @E00N777 View on GitHub
clang ClangIR
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

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.