[clang] [LifetimeSafety] Suggest lifetime annotations (PR #169767)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 28 06:38:56 PST 2025


================
@@ -65,7 +66,31 @@ class LifetimeChecker {
       for (const Fact *F : FactMgr.getFacts(B))
         if (const auto *EF = F->getAs<ExpireFact>())
           checkExpiry(EF);
+        else if (const auto *OEF = F->getAs<OriginEscapesFact>())
+          checkAnnotations(OEF);
     issuePendingWarnings();
+    issueAnnotationWarnings();
+  }
+
+  /// Checks if an escaping origin holds a placeholder loan, indicating a
+  /// missing [[clang::lifetimebound]] annotation.
+  void checkAnnotations(const OriginEscapesFact *OEF) {
+    if (!Reporter)
+      return;
+    OriginID EscapedOID = OEF->getEscapedOriginID();
+    LoanSet EscapedLoans = LoanPropagation.getLoans(EscapedOID, OEF);
+    if (EscapedLoans.isEmpty())
+      return;
+    for (const Loan *L : FactMgr.getLoanMgr().getLoans()) {
----------------
usx95 wrote:

We should not be needing to iterate through all the loans. Just iterate through the EscapedLoans (ids) and get the corresponding loans from the `loanmanager::getLoan(LoanID)`

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


More information about the cfe-commits mailing list