[PATCH] D49826: [analyzer] NFC: Minor code reuse in simplifySVal().

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 12:30:05 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL338422: [analyzer] Reuse some code in simplifySVal(). (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49826?vs=157389&id=158360#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49826

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1236,11 +1236,21 @@
       return Sym == Val.getAsSymbol();
     }
 
+    SVal cache(SymbolRef Sym, SVal V) {
+      Cached[Sym] = V;
+      return V;
+    }
+
+    SVal skip(SymbolRef Sym) {
+      return cache(Sym, SVB.makeSymbolVal(Sym));
+    }
+
   public:
     Simplifier(ProgramStateRef State)
         : State(State), SVB(State->getStateManager().getSValBuilder()) {}
 
     SVal VisitSymbolData(const SymbolData *S) {
+      // No cache here.
       if (const llvm::APSInt *I =
               SVB.getKnownValue(State, SVB.makeSymbolVal(S)))
         return Loc::isLocType(S->getType()) ? (SVal)SVB.makeIntLocVal(*I)
@@ -1257,11 +1267,9 @@
         return I->second;
 
       SVal LHS = Visit(S->getLHS());
-      if (isUnchanged(S->getLHS(), LHS)) {
-        SVal V = SVB.makeSymbolVal(S);
-        Cached[S] = V;
-        return V;
-      }
+      if (isUnchanged(S->getLHS(), LHS))
+        return skip(S);
+
       SVal RHS;
       // By looking at the APSInt in the right-hand side of S, we cannot
       // figure out if it should be treated as a Loc or as a NonLoc.
@@ -1281,9 +1289,8 @@
         RHS = SVB.makeIntVal(S->getRHS());
       }
 
-      SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
-      Cached[S] = V;
-      return V;
+      return cache(
+          S, SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType()));
     }
 
     SVal VisitSymSymExpr(const SymSymExpr *S) {
@@ -1296,22 +1303,16 @@
       // and we don't know how to combine a LocAsInteger
       // with a concrete value.
       if (Loc::isLocType(S->getLHS()->getType()) !=
-          Loc::isLocType(S->getRHS()->getType())) {
-        SVal V = SVB.makeSymbolVal(S);
-        Cached[S] = V;
-        return V;
-      }
+          Loc::isLocType(S->getRHS()->getType()))
+        return skip(S);
 
       SVal LHS = Visit(S->getLHS());
       SVal RHS = Visit(S->getRHS());
-      if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {
-        SVal V = SVB.makeSymbolVal(S);
-        Cached[S] = V;
-        return V;
-      }
-      SVal V = SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType());
-      Cached[S] = V;
-      return V;
+      if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS))
+        return skip(S);
+
+      return cache(
+          S, SVB.evalBinOp(State, S->getOpcode(), LHS, RHS, S->getType()));
     }
 
     SVal VisitSymExpr(SymbolRef S) { return nonloc::SymbolVal(S); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49826.158360.patch
Type: text/x-patch
Size: 2717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180731/b7d47072/attachment.bin>


More information about the cfe-commits mailing list