Skip to content

Commit d7581c8

Browse files
More cleanup
1 parent 5dd0882 commit d7581c8

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

clang/include/clang/3C/AVarBoundsInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ class AVarBoundsInfo {
275275
// This method can return `nullptr` if there is no corresponding ProgramVar.
276276
// It's not obvious when a BoundsKey can be expected to have a ProgramVar, so
277277
// callers should typically check for null.
278-
ProgramVar *getProgramVar(BoundsKey VK);
278+
ProgramVar *getProgramVar(BoundsKey VK) const;
279279

280280
// Get the Scope of the provided BoundsKey.
281281
// This method returns nullptr if `getProgramVar(BK)` would return nullptr.
282-
const ProgramVarScope *getProgramVarScope(BoundsKey BK);
282+
const ProgramVarScope *getProgramVarScope(BoundsKey BK) const;
283283

284284
// Return true when BoundsKey `To` can be accessed from the scope of `from`.
285285
// Note that this returns false if either BoundsKey cannot be mapped to a

clang/lib/3C/AVarBoundsInfo.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ScopeVisitor {
122122
// bounds keys from scopes where this scope is an inner scope.
123123
std::set<BoundsKey> VisibleKeys;
124124

125-
AVarBoundsInfo *BI;
125+
const AVarBoundsInfo *BI;
126126
};
127127

128128
void AvarBoundsInference::mergeReachableProgramVars(
@@ -246,7 +246,7 @@ ABounds *AvarBoundsInference::getPreferredBound(BoundsKey BK) {
246246
llvm::errs() << "Lower bound pointer required for " << BK
247247
<< " but not available.\n";
248248

249-
auto &BKindMap = CurrIterInferBounds[BK];
249+
const auto &BKindMap = CurrIterInferBounds[BK];
250250
// Utility to check if the map contains a non-empty set of bounds for a
251251
// particular kind. This makes the following if statements much cleaner.
252252
auto HasBoundKind = [&BKindMap](ABounds::BoundsKind Kind) {
@@ -503,6 +503,10 @@ bool AvarBoundsInference::inferBounds(BoundsKey K, const AVarGraph &BKGraph,
503503
bool FromPB) {
504504
bool IsChanged = false;
505505

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.
506510
if (BI->hasLowerBound(K) &&
507511
BI->InvalidBounds.find(K) == BI->InvalidBounds.end()) {
508512
// Infer from potential bounds?
@@ -1152,17 +1156,16 @@ bool AVarBoundsInfo::needsFreshLowerBound(ConstraintVariable *CV) {
11521156
getBounds(BK) != nullptr;
11531157
}
11541158

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;
11611163
}
11621164

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;
11661169
}
11671170

11681171
bool AVarBoundsInfo::isInAccessibleScope(BoundsKey From, BoundsKey To) {

0 commit comments

Comments
 (0)