[clang] [LifetimeSafety] Detect expiry of loans to trivially destructed types (PR #168855)

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 20 23:24:10 PST 2025


================
@@ -66,6 +66,9 @@ void FactsGenerator::run() {
       else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
                    Element.getAs<CFGAutomaticObjDtor>())
         handleDestructor(*DtorOpt);
+      else if (std::optional<CFGLifetimeEnds> LifetimeEnds =
+                   Element.getAs<CFGLifetimeEnds>())
+        handleTrivialDestructors(*LifetimeEnds);
----------------
kashika0112 wrote:

Yes, there are duplicate ExpireFacts generated for the above example.
Example:
```
std::string* trivial_uar(){
    std::string *ptr;
    std::string x;
    ptr = &x;
    return ptr;
}
```

```
Function: trivial_uar
  Block B2:
  End of Block
  Block B1:
    Issue (0 (Path: x), ToOrigin: 0 (Expr: DeclRefExpr))
    OriginFlow (Dest: 1 (Expr: UnaryOperator), Src: 0 (Expr: DeclRefExpr))
    Use (2 (Decl: ptr), Write)
    OriginFlow (Dest: 2 (Decl: ptr), Src: 1 (Expr: UnaryOperator))
    Use (2 (Decl: ptr), Read)
    OriginFlow (Dest: 3 (Expr: ImplicitCastExpr), Src: 2 (Decl: ptr))
    Expire (0 (Path: x))
    Expire (0 (Path: x))
    OriginEscapes (3 (Expr: ImplicitCastExpr))
  End of Block
  Block B0:
  End of Block
  ```

https://github.com/llvm/llvm-project/pull/168855


More information about the cfe-commits mailing list