llvm-project
46bbbde1 - [LifetimeSafety] Add lifetimebound inference for std::make_unique (#191632)

Commit
8 days ago
[LifetimeSafety] Add lifetimebound inference for std::make_unique (#191632) Enhanced lifetime safety analysis to support `std::make_unique` by propagating `lifetimebound` attributes from constructor parameters to `make_unique` parameters. - Added special handling for `std::make_unique` in `inferLifetimeBoundAttribute()` to automatically propagate `lifetimebound` attributes from the constructed type's constructor parameters to the corresponding `make_unique` parameters - Extended GSL owner type handling in assignment operations within `FactsGenerator::VisitCXXOperatorCallExpr()` `std::make_unique` is a common factory function that forwards arguments to constructors. Without this enhancement, lifetime safety analysis couldn't detect when `make_unique` was being used to create objects with lifetimebound dependencies, leading to missed warnings about potential dangling references. This change ensures that lifetime safety analysis works seamlessly with modern C++ idioms using smart pointer factory functions. --- **Current Limitation**: Lifetimebound propagation only occurs when the constructor parameter is a reference type. This restriction avoids incorrect loan tracking when value types (pointers, view types like `string_view`) are passed through forwarding references to `make_unique`. However, this means some legitimate dangling scenarios involving value-type parameters are not detected. This limitation presents an opportunity to experiment with `clang::lifetimebound(2)` to distinguish between parameter categories and enable more precise tracking for forwarding references and multi-level pointers in general. _(AI-assisted with HITL)_
Author
Parents
Loading