================
@@ -175,27 +179,90 @@ class LifetimeChecker {
FinalWarningsMap[ExpiredLoan] = {/*ExpiryLoc=*/EF->getExpiryLoc(),
/*BestCausingFact=*/BestCausingFact,
/*MovedExpr=*/MovedExpr,
+ /*InvalidatedByExpr=*/nullptr,
/*ConfidenceLevel=*/CurConfidence};
}
+ /// Checks for use-after-invalidation errors when a container is modified.
+ ///
+ /// This method identifies origins that are live at the point of invalidation
+ /// and checks if they hold loans that are invalidated by the operation
+ /// (e.g., iterators into a vector that is being pushed to).
+ void checkInvalidation(const InvalidateOriginFact *IOF) {
+ OriginID InvalidatedOrigin = IOF->getInvalidatedOrigin();
+ /// Get loans directly pointing to the invalidated container
+ LoanSet DirectlyInvalidatedLoans =
+ LoanPropagation.getLoans(InvalidatedOrigin, IOF);
+ auto IsInvalidated = [&](const Loan *L) {
+ auto *PathL = dyn_cast<PathLoan>(L);
+ auto *PlaceholderL = dyn_cast<PlaceholderLoan>(L);
+ for (LoanID InvalidID : DirectlyInvalidatedLoans) {
+ const Loan *L = FactMgr.getLoanMgr().getLoan(InvalidID);
+ auto *InvalidPathL = dyn_cast<PathLoan>(L);
+ auto *InvalidPlaceholderL = dyn_cast<PlaceholderLoan>(L);
+ if (PathL && InvalidPathL &&
+ PathL->getAccessPath() == InvalidPathL->getAccessPath())
+ return true;
+ if (PlaceholderL && InvalidPlaceholderL &&
+ PlaceholderL->getParmVarDecl() ==
+ InvalidPlaceholderL->getParmVarDecl())
+ return true;
+ }
+ return false;
+ };
+ // For each live origin, check if it holds an invalidated loan and report.
+ LivenessMap Origins = LiveOrigins.getLiveOriginsAt(IOF);
+ for (auto &[OID, LiveInfo] : Origins) {
+ LoanSet HeldLoans = LoanPropagation.getLoans(OID, IOF);
+ for (LoanID LiveLoanID : HeldLoans)
+ if (IsInvalidated(FactMgr.getLoanMgr().getLoan(LiveLoanID))) {
+ Confidence CurConfidence = livenessKindToConfidence(LiveInfo.Kind);
+ Confidence LastConf =
+ FinalWarningsMap.lookup(LiveLoanID).ConfidenceLevel;
+ if (LastConf < CurConfidence) {
----------------
usx95 wrote:
Yeah. I share your concerns. And I want to revamp this completely, get rid of
confidence and have different maps of warnings for different categories of this
analysis. I will do this in a later PR.
https://github.com/llvm/llvm-project/pull/179093
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits