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

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 28 07:30:12 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()) {
----------------
kashika0112 wrote:

Modified the code as per this.

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


More information about the cfe-commits mailing list