@@ -901,8 +901,8 @@ struct ExpiredLattice {
901901 OS << " ExpiredLattice State:\n " ;
902902 if (Expired.isEmpty ())
903903 OS << " <empty>\n " ;
904- for (const auto &ID_ : Expired)
905- OS << " Loan " << ID_. first << " is expired\n " ;
904+ for (const auto &[ID, _] : Expired)
905+ OS << " Loan " << ID << " is expired\n " ;
906906 }
907907};
908908
@@ -928,8 +928,10 @@ class ExpiredLoansAnalysis
928928 Lattice join (Lattice L1, Lattice L2) {
929929 return Lattice (
930930 utils::join (L1.Expired , L2.Expired , Factory,
931- // Take any ExpireFact to join the values.
932- [](const ExpireFact *F, const ExpireFact *) { return F; }));
931+ // Take the last expiry fact to make this hermetic.
932+ [](const ExpireFact *F1, const ExpireFact *F2) {
933+ return F1->getExpiryLoc () > F2->getExpiryLoc () ? F1 : F2;
934+ }));
933935 }
934936
935937 Lattice transfer (Lattice In, const ExpireFact &F) {
@@ -975,10 +977,9 @@ class ExpiredLoansAnalysis
975977
976978// / Struct to store the complete context for a potential lifetime violation.
977979struct PendingWarning {
978- const Expr *IssueExpr; // Where the loan was originally issued.
979980 SourceLocation ExpiryLoc; // Where the loan expired.
980981 const Expr *UseExpr; // Where the origin holding this loan was used.
981- Confidence Level ;
982+ Confidence ConfidenceLevel ;
982983};
983984
984985class LifetimeChecker {
@@ -1052,28 +1053,26 @@ class LifetimeChecker {
10521053 // If we already have a warning for this loan with a higher or equal
10531054 // confidence, skip this one.
10541055 if (FinalWarningsMap.count (DefaultedLoan) &&
1055- CurrentConfidence <= FinalWarningsMap[DefaultedLoan].Level )
1056+ CurrentConfidence <= FinalWarningsMap[DefaultedLoan].ConfidenceLevel )
10561057 continue ;
10571058
1058- const Loan &L = FactMgr.getLoanMgr ().getLoan (DefaultedLoan);
10591059 auto *EF = AllExpiredLoans.lookup (DefaultedLoan);
10601060 assert (EF && " Could not find ExpireFact for an expired loan." );
10611061
1062- const Expr *IssueExpr = L.IssueExpr ;
1063- SourceLocation ExpiryLoc = dyn_cast<ExpireFact>(*EF)->getExpiryLoc ();
1064-
1065- FinalWarningsMap[DefaultedLoan] = {IssueExpr, ExpiryLoc, UF->getUseExpr (),
1066- CurrentConfidence};
1062+ FinalWarningsMap[DefaultedLoan] = {/* ExpiryLoc=*/ (*EF)->getExpiryLoc (),
1063+ /* UseExpr=*/ UF->getUseExpr (),
1064+ /* ConfidenceLevel=*/ CurrentConfidence};
10671065 }
10681066 }
10691067
10701068 void issuePendingWarnings () {
10711069 if (!Reporter)
10721070 return ;
1073- for (const auto &pair : FinalWarningsMap) {
1074- const PendingWarning &PW = pair.second ;
1075- Reporter->reportUseAfterFree (PW.IssueExpr , PW.UseExpr , PW.ExpiryLoc ,
1076- PW.Level );
1071+ for (const auto &[LID, Warning] : FinalWarningsMap) {
1072+ const Loan &L = FactMgr.getLoanMgr ().getLoan (LID);
1073+ const Expr *IssueExpr = L.IssueExpr ;
1074+ Reporter->reportUseAfterFree (IssueExpr, Warning.UseExpr ,
1075+ Warning.ExpiryLoc , Warning.ConfidenceLevel );
10771076 }
10781077 }
10791078};
0 commit comments