> The initial implementation targets intra-procedural analysis for C++ raw pointers. This keeps the surface area small while we iterate. Over time, we aim to enable this analysis by default in Clang, with both “permissive” and “strict” modes to balance noise and coverage.
Key Components
- Conceptual Model: Introduces the fundamental concepts of Loan, Origin, and Path to model memory borrows and the lifetime of pointers.
- Fact Generation: A frontend pass traverses the Clang CFG to generate a representation of lifetime-relevant events, such as pointer assignments, taking an address, and variables going out of scope.
- Testing: llvm-lit tests validate the analysis by checking the generated facts.
Example:
[LifetimeSafety] Introduce intra-procedural analysis in Clang
https://discourse.llvm.org/t/announcing-the-lifetime-safety-...
Lifetime Analysis: Current Status
> For those not already familiar, we’re working on a new lifetime analysis in Clang to catch issues like use-after-scope or returning pointers to stack memory. The analysis is alias-based and draws inspiration from Rust’s borrow checker (specifically, [Polonius](https://smallcultfollowing.com/babysteps/blog/2018/04/27/an-...)). More details in the RFC: https://discourse.llvm.org/t/rfc-intra-procedural-lifetime-a...
> The initial implementation targets intra-procedural analysis for C++ raw pointers. This keeps the surface area small while we iterate. Over time, we aim to enable this analysis by default in Clang, with both “permissive” and “strict” modes to balance noise and coverage.
Key Components
- Conceptual Model: Introduces the fundamental concepts of Loan, Origin, and Path to model memory borrows and the lifetime of pointers.
- Fact Generation: A frontend pass traverses the Clang CFG to generate a representation of lifetime-relevant events, such as pointer assignments, taking an address, and variables going out of scope.
- Testing: llvm-lit tests validate the analysis by checking the generated facts.
Example:
[LifetimeSafety] Introduce intra-procedural analysis in Clang
Commit: https://github.com/llvm/llvm-project/commit/3076794e924f
PR: https://github.com/llvm/llvm-project/pull/142313
Test source code: https://github.com/llvm/llvm-project/blob/3076794e924f30ae21...