[all-commits] [llvm/llvm-project] 46bbbd: [LifetimeSafety] Add lifetimebound inference for s...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Thu Apr 16 06:07:08 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 46bbbde1f3c3bf3a00ae19c3157f7425899b1e87
      https://github.com/llvm/llvm-project/commit/46bbbde1f3c3bf3a00ae19c3157f7425899b1e87
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2026-04-16 (Thu, 16 Apr 2026)

  Changed paths:
    M clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
    M clang/lib/Analysis/LifetimeSafety/Origins.cpp
    M clang/lib/Sema/SemaAttr.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/test/Sema/Inputs/lifetime-analysis.h
    M clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
    M clang/test/Sema/warn-lifetime-safety-dangling-field.cpp
    M clang/test/Sema/warn-lifetime-safety-suggestions.cpp
    M clang/test/Sema/warn-lifetime-safety.cpp

  Log Message:
  -----------
  [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)_



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list