@@ -1236,11 +1236,21 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
1236
1236
return Sym == Val.getAsSymbol ();
1237
1237
}
1238
1238
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
+
1239
1248
public:
1240
1249
Simplifier (ProgramStateRef State)
1241
1250
: State(State), SVB(State->getStateManager ().getSValBuilder()) {}
1242
1251
1243
1252
SVal VisitSymbolData (const SymbolData *S) {
1253
+ // No cache here.
1244
1254
if (const llvm::APSInt *I =
1245
1255
SVB.getKnownValue (State, SVB.makeSymbolVal (S)))
1246
1256
return Loc::isLocType (S->getType ()) ? (SVal)SVB.makeIntLocVal (*I)
@@ -1257,11 +1267,9 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
1257
1267
return I->second ;
1258
1268
1259
1269
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
+
1265
1273
SVal RHS;
1266
1274
// By looking at the APSInt in the right-hand side of S, we cannot
1267
1275
// 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) {
1281
1289
RHS = SVB.makeIntVal (S->getRHS ());
1282
1290
}
1283
1291
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 ()));
1287
1294
}
1288
1295
1289
1296
SVal VisitSymSymExpr (const SymSymExpr *S) {
@@ -1296,22 +1303,16 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
1296
1303
// and we don't know how to combine a LocAsInteger
1297
1304
// with a concrete value.
1298
1305
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);
1304
1308
1305
1309
SVal LHS = Visit (S->getLHS ());
1306
1310
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 ()));
1315
1316
}
1316
1317
1317
1318
SVal VisitSymExpr (SymbolRef S) { return nonloc::SymbolVal (S); }
0 commit comments