Skip to content

Commit 8ee3dfd

Browse files
committed
[analyzer][NFC] Take SVal and NonLoc by value
1 parent 7619050 commit 8ee3dfd

14 files changed

+71
-89
lines changed

clang/include/clang/StaticAnalyzer/Core/Checker.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,8 @@ class PostCall {
193193

194194
class Location {
195195
template <typename CHECKER>
196-
static void _checkLocation(void *checker,
197-
const SVal &location, bool isLoad, const Stmt *S,
198-
CheckerContext &C) {
196+
static void _checkLocation(void *checker, SVal location, bool isLoad,
197+
const Stmt *S, CheckerContext &C) {
199198
((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
200199
}
201200

@@ -209,8 +208,7 @@ class Location {
209208

210209
class Bind {
211210
template <typename CHECKER>
212-
static void _checkBind(void *checker,
213-
const SVal &location, const SVal &val, const Stmt *S,
211+
static void _checkBind(void *checker, SVal location, SVal val, const Stmt *S,
214212
CheckerContext &C) {
215213
((const CHECKER *)checker)->checkBind(location, val, S, C);
216214
}
@@ -456,10 +454,8 @@ namespace eval {
456454

457455
class Assume {
458456
template <typename CHECKER>
459-
static ProgramStateRef _evalAssume(void *checker,
460-
ProgramStateRef state,
461-
const SVal &cond,
462-
bool assumption) {
457+
static ProgramStateRef _evalAssume(void *checker, ProgramStateRef state,
458+
SVal cond, bool assumption) {
463459
return ((const CHECKER *)checker)->evalAssume(state, cond, assumption);
464460
}
465461

clang/include/clang/StaticAnalyzer/Core/CheckerManager.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,11 @@ class CheckerManager {
488488
using CheckCallFunc =
489489
CheckerFn<void (const CallEvent &, CheckerContext &)>;
490490

491-
using CheckLocationFunc =
492-
CheckerFn<void (const SVal &location, bool isLoad, const Stmt *S,
493-
CheckerContext &)>;
491+
using CheckLocationFunc = CheckerFn<void(SVal location, bool isLoad,
492+
const Stmt *S, CheckerContext &)>;
494493

495494
using CheckBindFunc =
496-
CheckerFn<void (const SVal &location, const SVal &val, const Stmt *S,
497-
CheckerContext &)>;
495+
CheckerFn<void(SVal location, SVal val, const Stmt *S, CheckerContext &)>;
498496

499497
using CheckEndAnalysisFunc =
500498
CheckerFn<void (ExplodedGraph &, BugReporter &, ExprEngine &)>;
@@ -530,8 +528,7 @@ class CheckerManager {
530528
RegionAndSymbolInvalidationTraits *ITraits)>;
531529

532530
using EvalAssumeFunc =
533-
CheckerFn<ProgramStateRef (ProgramStateRef, const SVal &cond,
534-
bool assumption)>;
531+
CheckerFn<ProgramStateRef(ProgramStateRef, SVal cond, bool assumption)>;
535532

536533
using EvalCallFunc = CheckerFn<bool (const CallEvent &, CheckerContext &)>;
537534

clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ class CallAndMessageChecker
125125
if (!BT)
126126
BT.reset(new BugType(OriginalName, desc));
127127
}
128-
bool uninitRefOrPointer(CheckerContext &C, const SVal &V,
129-
SourceRange ArgRange, const Expr *ArgEx,
130-
std::unique_ptr<BugType> &BT,
128+
bool uninitRefOrPointer(CheckerContext &C, SVal V, SourceRange ArgRange,
129+
const Expr *ArgEx, std::unique_ptr<BugType> &BT,
131130
const ParmVarDecl *ParamDecl, const char *BD,
132131
int ArgumentNumber) const;
133132
};
@@ -185,7 +184,7 @@ static void describeUninitializedArgumentInCall(const CallEvent &Call,
185184
}
186185

187186
bool CallAndMessageChecker::uninitRefOrPointer(
188-
CheckerContext &C, const SVal &V, SourceRange ArgRange, const Expr *ArgEx,
187+
CheckerContext &C, SVal V, SourceRange ArgRange, const Expr *ArgEx,
189188
std::unique_ptr<BugType> &BT, const ParmVarDecl *ParamDecl, const char *BD,
190189
int ArgumentNumber) const {
191190

@@ -263,7 +262,7 @@ class FindUninitializedField {
263262
if (Find(FR))
264263
return true;
265264
} else {
266-
const SVal &V = StoreMgr.getBinding(store, loc::MemRegionVal(FR));
265+
SVal V = StoreMgr.getBinding(store, loc::MemRegionVal(FR));
267266
if (V.isUndef())
268267
return true;
269268
}

clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class InvalidatedIteratorChecker
3434
const BugType InvalidatedBugType{this, "Iterator invalidated",
3535
"Misuse of STL APIs"};
3636

37-
void verifyAccess(CheckerContext &C, const SVal &Val) const;
37+
void verifyAccess(CheckerContext &C, SVal Val) const;
3838
void reportBug(StringRef Message, SVal Val, CheckerContext &C,
3939
ExplodedNode *ErrNode) const;
4040

@@ -109,7 +109,8 @@ void InvalidatedIteratorChecker::checkPreStmt(const MemberExpr *ME,
109109
verifyAccess(C, BaseVal);
110110
}
111111

112-
void InvalidatedIteratorChecker::verifyAccess(CheckerContext &C, const SVal &Val) const {
112+
void InvalidatedIteratorChecker::verifyAccess(CheckerContext &C,
113+
SVal Val) const {
113114
auto State = C.getState();
114115
const auto *Pos = getIteratorPosition(State, Val);
115116
if (Pos && !Pos->isValid()) {

clang/lib/StaticAnalyzer/Checkers/Iterator.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ const ContainerData *getContainerData(ProgramStateRef State,
181181
return State->get<ContainerMap>(Cont);
182182
}
183183

184-
const IteratorPosition *getIteratorPosition(ProgramStateRef State,
185-
const SVal &Val) {
184+
const IteratorPosition *getIteratorPosition(ProgramStateRef State, SVal Val) {
186185
if (auto Reg = Val.getAsRegion()) {
187186
Reg = Reg->getMostDerivedObjectRegion();
188187
return State->get<IteratorRegionMap>(Reg);
@@ -194,7 +193,7 @@ const IteratorPosition *getIteratorPosition(ProgramStateRef State,
194193
return nullptr;
195194
}
196195

197-
ProgramStateRef setIteratorPosition(ProgramStateRef State, const SVal &Val,
196+
ProgramStateRef setIteratorPosition(ProgramStateRef State, SVal Val,
198197
const IteratorPosition &Pos) {
199198
if (auto Reg = Val.getAsRegion()) {
200199
Reg = Reg->getMostDerivedObjectRegion();
@@ -207,8 +206,8 @@ ProgramStateRef setIteratorPosition(ProgramStateRef State, const SVal &Val,
207206
return nullptr;
208207
}
209208

210-
ProgramStateRef createIteratorPosition(ProgramStateRef State, const SVal &Val,
211-
const MemRegion *Cont, const Stmt* S,
209+
ProgramStateRef createIteratorPosition(ProgramStateRef State, SVal Val,
210+
const MemRegion *Cont, const Stmt *S,
212211
const LocationContext *LCtx,
213212
unsigned blockCount) {
214213
auto &StateMgr = State->getStateManager();
@@ -221,9 +220,8 @@ ProgramStateRef createIteratorPosition(ProgramStateRef State, const SVal &Val,
221220
IteratorPosition::getPosition(Cont, Sym));
222221
}
223222

224-
ProgramStateRef advancePosition(ProgramStateRef State, const SVal &Iter,
225-
OverloadedOperatorKind Op,
226-
const SVal &Distance) {
223+
ProgramStateRef advancePosition(ProgramStateRef State, SVal Iter,
224+
OverloadedOperatorKind Op, SVal Distance) {
227225
const auto *Pos = getIteratorPosition(State, Iter);
228226
if (!Pos)
229227
return nullptr;

clang/lib/StaticAnalyzer/Checkers/Iterator.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,15 @@ bool isRandomIncrOrDecrOperator(OverloadedOperatorKind OK);
161161
bool isRandomIncrOrDecrOperator(BinaryOperatorKind OK);
162162
const ContainerData *getContainerData(ProgramStateRef State,
163163
const MemRegion *Cont);
164-
const IteratorPosition *getIteratorPosition(ProgramStateRef State,
165-
const SVal &Val);
166-
ProgramStateRef setIteratorPosition(ProgramStateRef State, const SVal &Val,
164+
const IteratorPosition *getIteratorPosition(ProgramStateRef State, SVal Val);
165+
ProgramStateRef setIteratorPosition(ProgramStateRef State, SVal Val,
167166
const IteratorPosition &Pos);
168-
ProgramStateRef createIteratorPosition(ProgramStateRef State, const SVal &Val,
169-
const MemRegion *Cont, const Stmt* S,
167+
ProgramStateRef createIteratorPosition(ProgramStateRef State, SVal Val,
168+
const MemRegion *Cont, const Stmt *S,
170169
const LocationContext *LCtx,
171170
unsigned blockCount);
172-
ProgramStateRef advancePosition(ProgramStateRef State,
173-
const SVal &Iter,
174-
OverloadedOperatorKind Op,
175-
const SVal &Distance);
171+
ProgramStateRef advancePosition(ProgramStateRef State, SVal Iter,
172+
OverloadedOperatorKind Op, SVal Distance);
176173
ProgramStateRef assumeNoOverflow(ProgramStateRef State, SymbolRef Sym,
177174
long Scale);
178175
bool compare(ProgramStateRef State, SymbolRef Sym1, SymbolRef Sym2,

clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,17 @@ class IteratorModeling
100100
const AdvanceFn *Handler) const;
101101

102102
void handleComparison(CheckerContext &C, const Expr *CE, SVal RetVal,
103-
const SVal &LVal, const SVal &RVal,
104-
OverloadedOperatorKind Op) const;
103+
SVal LVal, SVal RVal, OverloadedOperatorKind Op) const;
105104
void processComparison(CheckerContext &C, ProgramStateRef State,
106-
SymbolRef Sym1, SymbolRef Sym2, const SVal &RetVal,
105+
SymbolRef Sym1, SymbolRef Sym2, SVal RetVal,
107106
OverloadedOperatorKind Op) const;
108-
void handleIncrement(CheckerContext &C, const SVal &RetVal, const SVal &Iter,
107+
void handleIncrement(CheckerContext &C, SVal RetVal, SVal Iter,
109108
bool Postfix) const;
110-
void handleDecrement(CheckerContext &C, const SVal &RetVal, const SVal &Iter,
109+
void handleDecrement(CheckerContext &C, SVal RetVal, SVal Iter,
111110
bool Postfix) const;
112111
void handleRandomIncrOrDecr(CheckerContext &C, const Expr *CE,
113-
OverloadedOperatorKind Op, const SVal &RetVal,
114-
const SVal &Iterator, const SVal &Amount) const;
112+
OverloadedOperatorKind Op, SVal RetVal,
113+
SVal Iterator, SVal Amount) const;
115114
void handlePtrIncrOrDecr(CheckerContext &C, const Expr *Iterator,
116115
OverloadedOperatorKind OK, SVal Offset) const;
117116
void handleAdvance(CheckerContext &C, const Expr *CE, SVal RetVal, SVal Iter,
@@ -120,7 +119,7 @@ class IteratorModeling
120119
SVal Amount) const;
121120
void handleNext(CheckerContext &C, const Expr *CE, SVal RetVal, SVal Iter,
122121
SVal Amount) const;
123-
void assignToContainer(CheckerContext &C, const Expr *CE, const SVal &RetVal,
122+
void assignToContainer(CheckerContext &C, const Expr *CE, SVal RetVal,
124123
const MemRegion *Cont) const;
125124
bool noChangeInAdvance(CheckerContext &C, SVal Iter, const Expr *CE) const;
126125
void printState(raw_ostream &Out, ProgramStateRef State, const char *NL,
@@ -160,7 +159,7 @@ class IteratorModeling
160159

161160
bool isSimpleComparisonOperator(OverloadedOperatorKind OK);
162161
bool isSimpleComparisonOperator(BinaryOperatorKind OK);
163-
ProgramStateRef removeIteratorPosition(ProgramStateRef State, const SVal &Val);
162+
ProgramStateRef removeIteratorPosition(ProgramStateRef State, SVal Val);
164163
ProgramStateRef relateSymbols(ProgramStateRef State, SymbolRef Sym1,
165164
SymbolRef Sym2, bool Equal);
166165
bool isBoundThroughLazyCompoundVal(const Environment &Env,
@@ -283,7 +282,7 @@ void IteratorModeling::checkPostStmt(const BinaryOperator *BO,
283282
// The non-iterator side must have an integral or enumeration type.
284283
if (!AmountExpr->getType()->isIntegralOrEnumerationType())
285284
return;
286-
const SVal &AmountVal = IsIterOnLHS ? RVal : LVal;
285+
SVal AmountVal = IsIterOnLHS ? RVal : LVal;
287286
handlePtrIncrOrDecr(C, IterExpr, BinaryOperator::getOverloadedOperator(OK),
288287
AmountVal);
289288
}
@@ -388,8 +387,8 @@ IteratorModeling::handleOverloadedOperator(CheckerContext &C,
388387
const bool IsIterFirst = FirstType->isStructureOrClassType();
389388
const SVal FirstArg = Call.getArgSVal(0);
390389
const SVal SecondArg = Call.getArgSVal(1);
391-
const SVal &Iterator = IsIterFirst ? FirstArg : SecondArg;
392-
const SVal &Amount = IsIterFirst ? SecondArg : FirstArg;
390+
SVal Iterator = IsIterFirst ? FirstArg : SecondArg;
391+
SVal Amount = IsIterFirst ? SecondArg : FirstArg;
393392

394393
handleRandomIncrOrDecr(C, OrigExpr, Op, Call.getReturnValue(),
395394
Iterator, Amount);
@@ -444,14 +443,13 @@ IteratorModeling::handleAdvanceLikeFunction(CheckerContext &C,
444443
}
445444

446445
void IteratorModeling::handleComparison(CheckerContext &C, const Expr *CE,
447-
SVal RetVal, const SVal &LVal,
448-
const SVal &RVal,
449-
OverloadedOperatorKind Op) const {
446+
SVal RetVal, SVal LVal, SVal RVal,
447+
OverloadedOperatorKind Op) const {
450448
// Record the operands and the operator of the comparison for the next
451449
// evalAssume, if the result is a symbolic expression. If it is a concrete
452450
// value (only one branch is possible), then transfer the state between
453451
// the operands according to the operator and the result
454-
auto State = C.getState();
452+
auto State = C.getState();
455453
const auto *LPos = getIteratorPosition(State, LVal);
456454
const auto *RPos = getIteratorPosition(State, RVal);
457455
const MemRegion *Cont = nullptr;
@@ -504,7 +502,7 @@ void IteratorModeling::handleComparison(CheckerContext &C, const Expr *CE,
504502

505503
void IteratorModeling::processComparison(CheckerContext &C,
506504
ProgramStateRef State, SymbolRef Sym1,
507-
SymbolRef Sym2, const SVal &RetVal,
505+
SymbolRef Sym2, SVal RetVal,
508506
OverloadedOperatorKind Op) const {
509507
if (const auto TruthVal = RetVal.getAs<nonloc::ConcreteInt>()) {
510508
if ((State = relateSymbols(State, Sym1, Sym2,
@@ -532,8 +530,8 @@ void IteratorModeling::processComparison(CheckerContext &C,
532530
}
533531
}
534532

535-
void IteratorModeling::handleIncrement(CheckerContext &C, const SVal &RetVal,
536-
const SVal &Iter, bool Postfix) const {
533+
void IteratorModeling::handleIncrement(CheckerContext &C, SVal RetVal,
534+
SVal Iter, bool Postfix) const {
537535
// Increment the symbolic expressions which represents the position of the
538536
// iterator
539537
auto State = C.getState();
@@ -558,8 +556,8 @@ void IteratorModeling::handleIncrement(CheckerContext &C, const SVal &RetVal,
558556
C.addTransition(State);
559557
}
560558

561-
void IteratorModeling::handleDecrement(CheckerContext &C, const SVal &RetVal,
562-
const SVal &Iter, bool Postfix) const {
559+
void IteratorModeling::handleDecrement(CheckerContext &C, SVal RetVal,
560+
SVal Iter, bool Postfix) const {
563561
// Decrement the symbolic expressions which represents the position of the
564562
// iterator
565563
auto State = C.getState();
@@ -586,9 +584,8 @@ void IteratorModeling::handleDecrement(CheckerContext &C, const SVal &RetVal,
586584

587585
void IteratorModeling::handleRandomIncrOrDecr(CheckerContext &C, const Expr *CE,
588586
OverloadedOperatorKind Op,
589-
const SVal &RetVal,
590-
const SVal &Iterator,
591-
const SVal &Amount) const {
587+
SVal RetVal, SVal Iterator,
588+
SVal Amount) const {
592589
// Increment or decrement the symbolic expressions which represents the
593590
// position of the iterator
594591
auto State = C.getState();
@@ -684,7 +681,7 @@ void IteratorModeling::handleNext(CheckerContext &C, const Expr *CE,
684681
}
685682

686683
void IteratorModeling::assignToContainer(CheckerContext &C, const Expr *CE,
687-
const SVal &RetVal,
684+
SVal RetVal,
688685
const MemRegion *Cont) const {
689686
Cont = Cont->getMostDerivedObjectRegion();
690687

@@ -772,7 +769,7 @@ bool isSimpleComparisonOperator(BinaryOperatorKind OK) {
772769
return OK == BO_EQ || OK == BO_NE;
773770
}
774771

775-
ProgramStateRef removeIteratorPosition(ProgramStateRef State, const SVal &Val) {
772+
ProgramStateRef removeIteratorPosition(ProgramStateRef State, SVal Val) {
776773
if (auto Reg = Val.getAsRegion()) {
777774
Reg = Reg->getMostDerivedObjectRegion();
778775
return State->remove<IteratorRegionMap>(Reg);

clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class IteratorRangeChecker
6666
bool isPastTheEnd(ProgramStateRef State, const IteratorPosition &Pos);
6767
bool isAheadOfRange(ProgramStateRef State, const IteratorPosition &Pos);
6868
bool isBehindPastTheEnd(ProgramStateRef State, const IteratorPosition &Pos);
69-
bool isZero(ProgramStateRef State, const NonLoc &Val);
69+
bool isZero(ProgramStateRef State, NonLoc Val);
7070

7171
} //namespace
7272

@@ -289,7 +289,7 @@ bool isLess(ProgramStateRef State, SymbolRef Sym1, SymbolRef Sym2);
289289
bool isGreater(ProgramStateRef State, SymbolRef Sym1, SymbolRef Sym2);
290290
bool isEqual(ProgramStateRef State, SymbolRef Sym1, SymbolRef Sym2);
291291

292-
bool isZero(ProgramStateRef State, const NonLoc &Val) {
292+
bool isZero(ProgramStateRef State, NonLoc Val) {
293293
auto &BVF = State->getBasicVals();
294294
return compare(State, Val,
295295
nonloc::ConcreteInt(BVF.getValue(llvm::APSInt::get(0))),

0 commit comments

Comments
 (0)