[clang] [LifetimeSafety] Detect use-after-return (PR #165370)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 6 14:13:20 PST 2025


================
@@ -112,8 +114,17 @@ class LifetimeChecker {
     for (const auto &[LID, Warning] : FinalWarningsMap) {
       const Loan &L = FactMgr.getLoanMgr().getLoan(LID);
       const Expr *IssueExpr = L.IssueExpr;
-      Reporter->reportUseAfterFree(IssueExpr, Warning.UseExpr,
-                                   Warning.ExpiryLoc, Warning.ConfidenceLevel);
+      const Fact *CausingFact = Warning.CausingFact;
+      Confidence Confidence = Warning.ConfidenceLevel;
+      SourceLocation ExpiryLoc = Warning.ExpiryLoc;
+
+      if (const auto *UF = CausingFact->getAs<UseFact>()) {
+        Reporter->reportUseAfterFree(IssueExpr, UF->getUseExpr(), ExpiryLoc,
+                                     Confidence);
+      } else if (const auto *OEF = CausingFact->getAs<OriginEscapesFact>()) {
----------------
usx95 wrote:

nit: remove braces for a single statement if-else-body.
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

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


More information about the cfe-commits mailing list