Skip to content

Commit 9fe9a95

Browse files
committed
[analyzer] Reuse some code in simplifySVal().
No functional change intended. Differential Revision: https://reviews.llvm.org/D49826 llvm-svn: 338422
1 parent feedabf commit 9fe9a95

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,21 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12361236
return Sym == Val.getAsSymbol();
12371237
}
12381238

1239+
SVal cache(SymbolRef Sym, SVal V) {
1240+
Cached[Sym] = V;
1241+
return V;
1242+
}
1243+
1244+
SVal skip(SymbolRef Sym) {
1245+
return cache(Sym, SVB.makeSymbolVal(Sym));
1246+
}
1247+
12391248
public:
12401249
Simplifier(ProgramStateRef State)
12411250
: State(State), SVB(State->getStateManager().getSValBuilder()) {}
12421251

12431252
SVal VisitSymbolData(const SymbolData *S) {
1253+
// No cache here.
12441254
if (const llvm::APSInt *I =
12451255
SVB.getKnownValue(State, SVB.makeSymbolVal(S)))
12461256
return Loc::isLocType(S->getType()) ? (SVal)SVB.makeIntLocVal(*I)
@@ -1257,11 +1267,9 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12571267
return I->second;
12581268

12591269
SVal LHS = Visit(S->getLHS());
1260-
if (isUnchanged(S->getLHS(), LHS)) {
1261-
SVal V = SVB.makeSymbolVal(S);
1262-
Cached[S] = V;
1263-
return V;
1264-
}
1270+
if (isUnchanged(S->getLHS(), LHS))
1271+
return skip(S);
1272+
12651273
SVal RHS;
12661274
// By looking at the APSInt in the right-hand side of S, we cannot
12671275
// figure out if it should be treated as a Loc or as a NonLoc.
@@ -1281,9 +1289,8 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12811289
RHS = SVB.makeIntVal(S->getRHS());
12821290
}
12831291

1284-
SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
1285-
Cached[S] = V;
1286-
return V;
1292+
return cache(
1293+
S, SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType()));
12871294
}
12881295

12891296
SVal VisitSymSymExpr(const SymSymExpr *S) {
@@ -1296,22 +1303,16 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12961303
// and we don't know how to combine a LocAsInteger
12971304
// with a concrete value.
12981305
if (Loc::isLocType(S->getLHS()->getType()) !=
1299-
Loc::isLocType(S->getRHS()->getType())) {
1300-
SVal V = SVB.makeSymbolVal(S);
1301-
Cached[S] = V;
1302-
return V;
1303-
}
1306+
Loc::isLocType(S->getRHS()->getType()))
1307+
return skip(S);
13041308

13051309
SVal LHS = Visit(S->getLHS());
13061310
SVal RHS = Visit(S->getRHS());
1307-
if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {
1308-
SVal V = SVB.makeSymbolVal(S);
1309-
Cached[S] = V;
1310-
return V;
1311-
}
1312-
SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
1313-
Cached[S] = V;
1314-
return V;
1311+
if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
1312+
return skip(S);
1313+
1314+
return cache(
1315+
S, SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType()));
13151316
}
13161317

13171318
SVal VisitSymExpr(SymbolRef S) { return nonloc::SymbolVal(S); }

0 commit comments

Comments
 (0)