@@ -122,7 +122,7 @@ class ScopeVisitor {
122
122
// bounds keys from scopes where this scope is an inner scope.
123
123
std::set<BoundsKey> VisibleKeys;
124
124
125
- AVarBoundsInfo *BI;
125
+ const AVarBoundsInfo *BI;
126
126
};
127
127
128
128
void AvarBoundsInference::mergeReachableProgramVars (
@@ -246,7 +246,7 @@ ABounds *AvarBoundsInference::getPreferredBound(BoundsKey BK) {
246
246
llvm::errs () << " Lower bound pointer required for " << BK
247
247
<< " but not available.\n " ;
248
248
249
- auto &BKindMap = CurrIterInferBounds[BK];
249
+ const auto &BKindMap = CurrIterInferBounds[BK];
250
250
// Utility to check if the map contains a non-empty set of bounds for a
251
251
// particular kind. This makes the following if statements much cleaner.
252
252
auto HasBoundKind = [&BKindMap](ABounds::BoundsKind Kind) {
@@ -503,6 +503,10 @@ bool AvarBoundsInference::inferBounds(BoundsKey K, const AVarGraph &BKGraph,
503
503
bool FromPB) {
504
504
bool IsChanged = false ;
505
505
506
+ // If a lower bound could not be inferred for a BoundsKey, then we refuse to
507
+ // infer an upper bound for it as well. This prevents inferring incorrect
508
+ // bounds when a bound would propagate through a pointer without a lower
509
+ // bound.
506
510
if (BI->hasLowerBound (K) &&
507
511
BI->InvalidBounds .find (K) == BI->InvalidBounds .end ()) {
508
512
// Infer from potential bounds?
@@ -1152,17 +1156,16 @@ bool AVarBoundsInfo::needsFreshLowerBound(ConstraintVariable *CV) {
1152
1156
getBounds (BK) != nullptr ;
1153
1157
}
1154
1158
1155
- ProgramVar *AVarBoundsInfo::getProgramVar (BoundsKey VK) {
1156
- ProgramVar *Ret = nullptr ;
1157
- if (PVarInfo.find (VK) != PVarInfo.end ()) {
1158
- Ret = PVarInfo[VK];
1159
- }
1160
- return Ret;
1159
+ ProgramVar *AVarBoundsInfo::getProgramVar (BoundsKey VK) const {
1160
+ if (PVarInfo.find (VK) != PVarInfo.end ())
1161
+ return PVarInfo.at (VK);
1162
+ return nullptr ;
1161
1163
}
1162
1164
1163
- const ProgramVarScope *AVarBoundsInfo::getProgramVarScope (BoundsKey BK) {
1164
- ProgramVar *Var = getProgramVar (BK);
1165
- return Var == nullptr ? nullptr : Var->getScope ();
1165
+ const ProgramVarScope *AVarBoundsInfo::getProgramVarScope (BoundsKey BK) const {
1166
+ if (ProgramVar *Var = getProgramVar (BK))
1167
+ return Var->getScope ();
1168
+ return nullptr ;
1166
1169
}
1167
1170
1168
1171
bool AVarBoundsInfo::isInAccessibleScope (BoundsKey From, BoundsKey To) {
0 commit comments