diff options
Diffstat (limited to 'clang/include')
4 files changed, 54 insertions, 13 deletions
diff --git a/clang/include/clang/Checker/PathSensitive/MemRegion.h b/clang/include/clang/Checker/PathSensitive/MemRegion.h index 8425c3bd62d..48a7ad2aab1 100644 --- a/clang/include/clang/Checker/PathSensitive/MemRegion.h +++ b/clang/include/clang/Checker/PathSensitive/MemRegion.h @@ -34,6 +34,7 @@ class MemRegionManager; class MemSpaceRegion; class LocationContext; class StackFrameContext; +class ValueManager; class VarRegion; class CodeTextRegion; @@ -266,6 +267,11 @@ public: return superRegion; } + /// getExtent - Returns the size of the region in bytes. + virtual DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const { + return UnknownVal(); + } + MemRegionManager* getMemRegionManager() const; bool isSubRegionOf(const MemRegion* R) const; @@ -322,6 +328,8 @@ public: bool isBoundable() const { return true; } + DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const; + void Profile(llvm::FoldingSetNodeID& ID) const; static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex, @@ -536,6 +544,8 @@ public: bool isBoundable() const { return true; } + DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const; + void Profile(llvm::FoldingSetNodeID& ID) const; static void ProfileRegion(llvm::FoldingSetNodeID& ID, @@ -570,6 +580,8 @@ public: return Str->getType(); } + DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const; + bool isBoundable() const { return false; } void Profile(llvm::FoldingSetNodeID& ID) const { @@ -629,6 +641,8 @@ public: const Decl* getDecl() const { return D; } void Profile(llvm::FoldingSetNodeID& ID) const; + DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const; + static bool classof(const MemRegion* R) { unsigned k = R->getKind(); return k >= BEG_DECL_REGIONS && k <= END_DECL_REGIONS; @@ -713,6 +727,8 @@ public: return C.getCanonicalType(getDecl()->getType()); } + DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const; + static void ProfileRegion(llvm::FoldingSetNodeID& ID, const FieldDecl* FD, const MemRegion* superRegion) { DeclRegion::ProfileRegion(ID, FD, superRegion, FieldRegionKind); diff --git a/clang/include/clang/Checker/PathSensitive/SValuator.h b/clang/include/clang/Checker/PathSensitive/SValuator.h index 5e3ba04a20c..9192ca7b861 100644 --- a/clang/include/clang/Checker/PathSensitive/SValuator.h +++ b/clang/include/clang/Checker/PathSensitive/SValuator.h @@ -52,6 +52,10 @@ public: virtual SVal EvalBinOpLN(const GRState *state, BinaryOperator::Opcode Op, Loc lhs, NonLoc rhs, QualType resultTy) = 0; + + /// getKnownValue - Evaluates a given SVal. If the SVal has only one possible + /// (integer) value, that value is returned. Otherwise, returns NULL. + virtual const llvm::APSInt *getKnownValue(const GRState *state, SVal V) = 0; SVal EvalBinOp(const GRState *ST, BinaryOperator::Opcode Op, SVal L, SVal R, QualType T); diff --git a/clang/include/clang/Checker/PathSensitive/Store.h b/clang/include/clang/Checker/PathSensitive/Store.h index 9becfe328ed..7a60ebb0838 100644 --- a/clang/include/clang/Checker/PathSensitive/Store.h +++ b/clang/include/clang/Checker/PathSensitive/Store.h @@ -114,7 +114,8 @@ public: virtual SVal getLValueElement(QualType elementType, SVal offset, SVal Base); - // FIXME: Make out-of-line. + // FIXME: This should soon be eliminated altogether; clients should deal with + // region extents directly. virtual DefinedOrUnknownSVal getSizeInElements(const GRState *state, const MemRegion *region, QualType EleTy) { @@ -171,17 +172,6 @@ public: InvalidatedSymbols *IS, bool invalidateGlobals) = 0; - // FIXME: Make out-of-line. - virtual const GRState *setExtent(const GRState *state, - const MemRegion *region, SVal extent) { - return state; - } - - virtual llvm::Optional<SVal> getExtent(const GRState *state, - const MemRegion *R) { - return llvm::Optional<SVal>(); - } - /// EnterStackFrame - Let the StoreManager to do something when execution /// engine is about to execute into a callee. virtual const GRState *EnterStackFrame(const GRState *state, diff --git a/clang/include/clang/Checker/PathSensitive/SymbolManager.h b/clang/include/clang/Checker/PathSensitive/SymbolManager.h index 681b3765eda..ffbd2892499 100644 --- a/clang/include/clang/Checker/PathSensitive/SymbolManager.h +++ b/clang/include/clang/Checker/PathSensitive/SymbolManager.h @@ -31,6 +31,7 @@ namespace clang { class ASTContext; class BasicValueFactory; class MemRegion; + class SubRegion; class TypedRegion; class VarRegion; class StackFrameContext; @@ -38,7 +39,7 @@ namespace clang { class SymExpr : public llvm::FoldingSetNode { public: enum Kind { BEGIN_SYMBOLS, - RegionValueKind, ConjuredKind, DerivedKind, + RegionValueKind, ConjuredKind, DerivedKind, ExtentKind, END_SYMBOLS, SymIntKind, SymSymKind }; private: @@ -189,6 +190,34 @@ public: } }; +class SymbolExtent : public SymbolData { + const SubRegion *R; + +public: + SymbolExtent(SymbolID sym, const SubRegion *r) + : SymbolData(ExtentKind, sym), R(r) {} + + const SubRegion *getRegion() const { return R; } + + QualType getType(ASTContext&) const; + + void dumpToStream(llvm::raw_ostream &os) const; + + static void Profile(llvm::FoldingSetNodeID& profile, const SubRegion *R) { + profile.AddInteger((unsigned) ExtentKind); + profile.AddPointer(R); + } + + virtual void Profile(llvm::FoldingSetNodeID& profile) { + Profile(profile, R); + } + + // Implement isa<T> support. + static inline bool classof(const SymExpr* SE) { + return SE->getKind() == ExtentKind; + } +}; + // SymIntExpr - Represents symbolic expression like 'x' + 3. class SymIntExpr : public SymExpr { const SymExpr *LHS; @@ -305,6 +334,8 @@ public: const SymbolDerived *getDerivedSymbol(SymbolRef parentSymbol, const TypedRegion *R); + const SymbolExtent *getExtentSymbol(const SubRegion *R); + const SymIntExpr *getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt& rhs, QualType t); |