[clang] [LifetimeSafety] Detect use-after-return (PR #165370)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 6 14:13:21 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>()) {
+ Reporter->reportUseAfterReturn(IssueExpr, OEF->getEscapeExpr(),
+ ExpiryLoc, Confidence);
+ }
----------------
usx95 wrote:
add a final `else` with `llvm_unreachable("unhandled causing fact");`
https://github.com/llvm/llvm-project/pull/165370
More information about the cfe-commits
mailing list