r286927 - [analyzer] Rename assumeWithinInclusiveRange*()

Dominic Chen via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 14 17:54:41 PST 2016


Author: ddcc
Date: Mon Nov 14 19:54:41 2016
New Revision: 286927

URL: http://llvm.org/viewvc/llvm-project?rev=286927&view=rev
Log:
[analyzer] Rename assumeWithinInclusiveRange*()

Summary: The name is slightly confusing, since the constraint is not necessarily within the range unless `Assumption` is true. Split out renaming for ConstraintManager.h from D26061

Reviewers: zaks.anna, dcoughlin

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26644

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
    cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h Mon Nov 14 19:54:41 2016
@@ -36,7 +36,7 @@ public:
 
   /// Construct a ConstraintVal indicating the constraint is underconstrained.
   ConditionTruthVal() {}
-  
+
   /// Return true if the constraint is perfectly constrained to 'true'.
   bool isConstrainedTrue() const {
     return Val.hasValue() && Val.getValue();
@@ -58,11 +58,11 @@ public:
     return !Val.hasValue();
   }
 };
-  
+
 class ConstraintManager {
 public:
   ConstraintManager() : NotifyAssumeClients(true) {}
-  
+
   virtual ~ConstraintManager();
   virtual ProgramStateRef assume(ProgramStateRef state,
                                  DefinedSVal Cond,
@@ -99,25 +99,26 @@ public:
     return ProgramStatePair(StTrue, StFalse);
   }
 
-  virtual ProgramStateRef assumeWithinInclusiveRange(ProgramStateRef State,
-                                                     NonLoc Value,
-                                                     const llvm::APSInt &From,
-                                                     const llvm::APSInt &To,
-                                                     bool InBound) = 0;
-
-  virtual ProgramStatePair assumeWithinInclusiveRangeDual(
-      ProgramStateRef State, NonLoc Value, const llvm::APSInt &From,
-      const llvm::APSInt &To) {
-    ProgramStateRef StInRange = assumeWithinInclusiveRange(State, Value, From,
-                                                           To, true);
+  virtual ProgramStateRef assumeInclusiveRange(ProgramStateRef State,
+                                               NonLoc Value,
+                                               const llvm::APSInt &From,
+                                               const llvm::APSInt &To,
+                                               bool InBound) = 0;
+
+  virtual ProgramStatePair assumeInclusiveRangeDual(ProgramStateRef State,
+                                                    NonLoc Value,
+                                                    const llvm::APSInt &From,
+                                                    const llvm::APSInt &To) {
+    ProgramStateRef StInRange =
+        assumeInclusiveRange(State, Value, From, To, true);
 
     // If StTrue is infeasible, asserting the falseness of Cond is unnecessary
     // because the existing constraints already establish this.
     if (!StInRange)
       return ProgramStatePair((ProgramStateRef)nullptr, State);
 
-    ProgramStateRef StOutOfRange = assumeWithinInclusiveRange(State, Value,
-                                                              From, To, false);
+    ProgramStateRef StOutOfRange =
+        assumeInclusiveRange(State, Value, From, To, false);
     if (!StOutOfRange) {
       // We are careful to return the original state, /not/ StTrue,
       // because we want to avoid having callers generate a new node
@@ -147,7 +148,7 @@ public:
                      const char *sep) = 0;
 
   virtual void EndPath(ProgramStateRef state) {}
-  
+
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
@@ -173,7 +174,7 @@ protected:
   virtual bool canReasonAbout(SVal X) const = 0;
 
   /// Returns whether or not a symbol is known to be null ("true"), known to be
-  /// non-null ("false"), or may be either ("underconstrained"). 
+  /// non-null ("false"), or may be either ("underconstrained").
   virtual ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym);
 };
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h Mon Nov 14 19:54:41 2016
@@ -98,18 +98,18 @@ public:
   /// This ctor is used when creating the first ProgramState object.
   ProgramState(ProgramStateManager *mgr, const Environment& env,
           StoreRef st, GenericDataMap gdm);
-    
+
   /// Copy ctor - We must explicitly define this or else the "Next" ptr
   ///  in FoldingSetNode will also get copied.
   ProgramState(const ProgramState &RHS);
-  
+
   ~ProgramState();
 
   /// Return the ProgramStateManager associated with this state.
   ProgramStateManager &getStateManager() const {
     return *stateMgr;
   }
-  
+
   /// Return the ConstraintManager.
   ConstraintManager &getConstraintManager() const;
 
@@ -121,7 +121,7 @@ public:
   ///  is a mapping from locations to values.
   Store getStore() const { return store; }
 
-  
+
   /// getGDM - Return the generic data map associated with this state.
   GenericDataMap getGDM() const { return GDM; }
 
@@ -197,10 +197,10 @@ public:
   ///
   /// This returns a new state with the added constraint on \p cond.
   /// If no new state is feasible, NULL is returned.
-  ProgramStateRef assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
-                                             const llvm::APSInt &From,
-                                             const llvm::APSInt &To,
-                                             bool assumption) const;
+  ProgramStateRef assumeInclusiveRange(DefinedOrUnknownSVal Val,
+                                       const llvm::APSInt &From,
+                                       const llvm::APSInt &To,
+                                       bool assumption) const;
 
   /// Assumes given range both "true" and "false" for \p Val, and returns both
   /// corresponding states (respectively).
@@ -208,14 +208,13 @@ public:
   /// This is more efficient than calling assume() twice. Note that one (but not
   /// both) of the returned states may be NULL.
   std::pair<ProgramStateRef, ProgramStateRef>
-  assumeWithinInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt &From,
-                             const llvm::APSInt &To) const;
+  assumeInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt &From,
+                       const llvm::APSInt &To) const;
 
-  
   /// \brief Check if the given SVal is constrained to zero or is a zero
   ///        constant.
   ConditionTruthVal isNull(SVal V) const;
-  
+
   /// Utility method for getting regions.
   const VarRegion* getRegion(const VarDecl *D, const LocationContext *LC) const;
 
@@ -254,7 +253,7 @@ public:
   /// \param IS the set of invalidated symbols.
   /// \param Call if non-null, the invalidated regions represent parameters to
   ///        the call and should be considered directly invalidated.
-  /// \param ITraits information about special handling for a particular 
+  /// \param ITraits information about special handling for a particular
   ///        region/symbol.
   ProgramStateRef
   invalidateRegions(ArrayRef<const MemRegion *> Regions, const Expr *E,
@@ -278,7 +277,7 @@ public:
   /// Get the lvalue for a variable reference.
   Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
 
-  Loc getLValue(const CompoundLiteralExpr *literal, 
+  Loc getLValue(const CompoundLiteralExpr *literal,
                 const LocationContext *LC) const;
 
   /// Get the lvalue for an ivar reference.
@@ -295,7 +294,7 @@ public:
 
   /// Returns the SVal bound to the statement 'S' in the state's environment.
   SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
-  
+
   SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const;
 
   /// \brief Return the value bound to the specified location.
@@ -310,7 +309,7 @@ public:
   SVal getSVal(const MemRegion* R) const;
 
   SVal getSValAsScalarOrLoc(const MemRegion *R) const;
-  
+
   /// \brief Visits the symbols reachable from the given SVal using the provided
   /// SymbolVisitor.
   ///
@@ -319,22 +318,22 @@ public:
   /// visitor to avoid repeated initialization cost.
   /// \sa ScanReachableSymbols
   bool scanReachableSymbols(SVal val, SymbolVisitor& visitor) const;
-  
+
   /// \brief Visits the symbols reachable from the SVals in the given range
   /// using the provided SymbolVisitor.
   bool scanReachableSymbols(const SVal *I, const SVal *E,
                             SymbolVisitor &visitor) const;
-  
+
   /// \brief Visits the symbols reachable from the regions in the given
   /// MemRegions range using the provided SymbolVisitor.
-  bool scanReachableSymbols(const MemRegion * const *I, 
+  bool scanReachableSymbols(const MemRegion * const *I,
                             const MemRegion * const *E,
                             SymbolVisitor &visitor) const;
 
   template <typename CB> CB scanReachableSymbols(SVal val) const;
   template <typename CB> CB scanReachableSymbols(const SVal *beg,
                                                  const SVal *end) const;
-  
+
   template <typename CB> CB
   scanReachableSymbols(const MemRegion * const *beg,
                        const MemRegion * const *end) const;
@@ -469,7 +468,7 @@ private:
 
   /// A BumpPtrAllocator to allocate states.
   llvm::BumpPtrAllocator &Alloc;
-  
+
   /// A vector of ProgramStates that we can reuse.
   std::vector<ProgramState *> freeStates;
 
@@ -632,9 +631,9 @@ public:
 inline ConstraintManager &ProgramState::getConstraintManager() const {
   return stateMgr->getConstraintManager();
 }
-  
+
 inline const VarRegion* ProgramState::getRegion(const VarDecl *D,
-                                                const LocationContext *LC) const 
+                                                const LocationContext *LC) const
 {
   return getStateManager().getRegionManager().getVarRegion(D, LC);
 }
@@ -647,7 +646,7 @@ inline ProgramStateRef ProgramState::ass
   return getStateManager().ConstraintMgr
       ->assume(this, Cond.castAs<DefinedSVal>(), Assumption);
 }
-  
+
 inline std::pair<ProgramStateRef , ProgramStateRef >
 ProgramState::assume(DefinedOrUnknownSVal Cond) const {
   if (Cond.isUnknown())
@@ -657,31 +656,29 @@ ProgramState::assume(DefinedOrUnknownSVa
       ->assumeDual(this, Cond.castAs<DefinedSVal>());
 }
 
-inline ProgramStateRef
-ProgramState::assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
-                                         const llvm::APSInt &From,
-                                         const llvm::APSInt &To,
-                                         bool Assumption) const {
+inline ProgramStateRef ProgramState::assumeInclusiveRange(
+    DefinedOrUnknownSVal Val, const llvm::APSInt &From, const llvm::APSInt &To,
+    bool Assumption) const {
   if (Val.isUnknown())
     return this;
 
   assert(Val.getAs<NonLoc>() && "Only NonLocs are supported!");
 
-  return getStateManager().ConstraintMgr->assumeWithinInclusiveRange(
-        this, Val.castAs<NonLoc>(), From, To, Assumption);
+  return getStateManager().ConstraintMgr->assumeInclusiveRange(
+      this, Val.castAs<NonLoc>(), From, To, Assumption);
 }
 
 inline std::pair<ProgramStateRef, ProgramStateRef>
-ProgramState::assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
-                                         const llvm::APSInt &From,
-                                         const llvm::APSInt &To) const {
+ProgramState::assumeInclusiveRange(DefinedOrUnknownSVal Val,
+                                   const llvm::APSInt &From,
+                                   const llvm::APSInt &To) const {
   if (Val.isUnknown())
     return std::make_pair(this, this);
 
   assert(Val.getAs<NonLoc>() && "Only NonLocs are supported!");
 
-  return getStateManager().ConstraintMgr
-      ->assumeWithinInclusiveRangeDual(this, Val.castAs<NonLoc>(), From, To);
+  return getStateManager().ConstraintMgr->assumeInclusiveRangeDual(
+      this, Val.castAs<NonLoc>(), From, To);
 }
 
 inline ProgramStateRef ProgramState::bindLoc(SVal LV, SVal V) const {
@@ -810,7 +807,7 @@ CB ProgramState::scanReachableSymbols(SV
   scanReachableSymbols(val, cb);
   return cb;
 }
-  
+
 template <typename CB>
 CB ProgramState::scanReachableSymbols(const SVal *beg, const SVal *end) const {
   CB cb(this);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp Mon Nov 14 19:54:41 2016
@@ -254,7 +254,7 @@ ProgramStateRef StdLibraryFunctionsCheck
       const llvm::APSInt &Min = BVF.getValue(R[I].first, T);
       const llvm::APSInt &Max = BVF.getValue(R[I].second, T);
       assert(Min <= Max);
-      State = CM.assumeWithinInclusiveRange(State, *N, Min, Max, false);
+      State = CM.assumeInclusiveRange(State, *N, Min, Max, false);
       if (!State)
         break;
     }
@@ -288,7 +288,7 @@ StdLibraryFunctionsChecker::ValueRange::
     const llvm::APSInt &Left = BVF.getValue(R[0].first - 1ULL, T);
     if (Left != PlusInf) {
       assert(MinusInf <= Left);
-      State = CM.assumeWithinInclusiveRange(State, *N, MinusInf, Left, false);
+      State = CM.assumeInclusiveRange(State, *N, MinusInf, Left, false);
       if (!State)
         return nullptr;
     }
@@ -296,7 +296,7 @@ StdLibraryFunctionsChecker::ValueRange::
     const llvm::APSInt &Right = BVF.getValue(R[E - 1].second + 1ULL, T);
     if (Right != MinusInf) {
       assert(Right <= PlusInf);
-      State = CM.assumeWithinInclusiveRange(State, *N, Right, PlusInf, false);
+      State = CM.assumeInclusiveRange(State, *N, Right, PlusInf, false);
       if (!State)
         return nullptr;
     }
@@ -305,7 +305,7 @@ StdLibraryFunctionsChecker::ValueRange::
       const llvm::APSInt &Min = BVF.getValue(R[I - 1].second + 1ULL, T);
       const llvm::APSInt &Max = BVF.getValue(R[I].first - 1ULL, T);
       assert(Min <= Max);
-      State = CM.assumeWithinInclusiveRange(State, *N, Min, Max, false);
+      State = CM.assumeInclusiveRange(State, *N, Min, Max, false);
       if (!State)
         return nullptr;
     }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Nov 14 19:54:41 2016
@@ -1836,7 +1836,7 @@ void ExprEngine::processSwitch(SwitchNod
     ProgramStateRef StateCase;
     if (Optional<NonLoc> NL = CondV.getAs<NonLoc>())
       std::tie(StateCase, DefaultSt) =
-          DefaultSt->assumeWithinInclusiveRange(*NL, V1, V2);
+          DefaultSt->assumeInclusiveRange(*NL, V1, V2);
     else // UnknownVal
       StateCase = DefaultSt;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp Mon Nov 14 19:54:41 2016
@@ -190,7 +190,7 @@ ProgramStateRef SimpleConstraintManager:
   } // end switch
 }
 
-ProgramStateRef SimpleConstraintManager::assumeWithinInclusiveRange(
+ProgramStateRef SimpleConstraintManager::assumeInclusiveRange(
     ProgramStateRef State, NonLoc Value, const llvm::APSInt &From,
     const llvm::APSInt &To, bool InRange) {
 
@@ -207,7 +207,7 @@ ProgramStateRef SimpleConstraintManager:
 
   switch (Value.getSubKind()) {
   default:
-    llvm_unreachable("'assumeWithinInclusiveRange' is not implemented"
+    llvm_unreachable("'assumeInclusiveRange' is not implemented"
                      "for this NonLoc");
 
   case nonloc::LocAsIntegerKind:

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h?rev=286927&r1=286926&r2=286927&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h Mon Nov 14 19:54:41 2016
@@ -38,7 +38,7 @@ public:
 
   ProgramStateRef assume(ProgramStateRef state, NonLoc Cond, bool Assumption);
 
-  ProgramStateRef assumeWithinInclusiveRange(ProgramStateRef State,
+  ProgramStateRef assumeInclusiveRange(ProgramStateRef State,
                                              NonLoc Value,
                                              const llvm::APSInt &From,
                                              const llvm::APSInt &To,




More information about the cfe-commits mailing list