@@ -901,8 +901,8 @@ struct ExpiredLattice {
901
901
OS << " ExpiredLattice State:\n " ;
902
902
if (Expired.isEmpty ())
903
903
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 " ;
906
906
}
907
907
};
908
908
@@ -928,8 +928,10 @@ class ExpiredLoansAnalysis
928
928
Lattice join (Lattice L1, Lattice L2) {
929
929
return Lattice (
930
930
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
+ }));
933
935
}
934
936
935
937
Lattice transfer (Lattice In, const ExpireFact &F) {
@@ -975,10 +977,9 @@ class ExpiredLoansAnalysis
975
977
976
978
// / Struct to store the complete context for a potential lifetime violation.
977
979
struct PendingWarning {
978
- const Expr *IssueExpr; // Where the loan was originally issued.
979
980
SourceLocation ExpiryLoc; // Where the loan expired.
980
981
const Expr *UseExpr; // Where the origin holding this loan was used.
981
- Confidence Level ;
982
+ Confidence ConfidenceLevel ;
982
983
};
983
984
984
985
class LifetimeChecker {
@@ -1052,28 +1053,26 @@ class LifetimeChecker {
1052
1053
// If we already have a warning for this loan with a higher or equal
1053
1054
// confidence, skip this one.
1054
1055
if (FinalWarningsMap.count (DefaultedLoan) &&
1055
- CurrentConfidence <= FinalWarningsMap[DefaultedLoan].Level )
1056
+ CurrentConfidence <= FinalWarningsMap[DefaultedLoan].ConfidenceLevel )
1056
1057
continue ;
1057
1058
1058
- const Loan &L = FactMgr.getLoanMgr ().getLoan (DefaultedLoan);
1059
1059
auto *EF = AllExpiredLoans.lookup (DefaultedLoan);
1060
1060
assert (EF && " Could not find ExpireFact for an expired loan." );
1061
1061
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};
1067
1065
}
1068
1066
}
1069
1067
1070
1068
void issuePendingWarnings () {
1071
1069
if (!Reporter)
1072
1070
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 );
1077
1076
}
1078
1077
}
1079
1078
};
0 commit comments