diff options
Diffstat (limited to 'include/clang/Analysis/PathSensitive')
-rw-r--r-- | include/clang/Analysis/PathSensitive/MemRegion.h | 59 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/SVals.h | 2 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/ValueManager.h | 11 |
3 files changed, 49 insertions, 23 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 65ac0b53027c8..5926229e517c3 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -62,7 +62,6 @@ protected: ASTContext &getContext() const; public: - // virtual MemExtent getExtent(MemRegionManager& mrm) const = 0; virtual void Profile(llvm::FoldingSetNodeID& ID) const = 0; virtual MemRegionManager* getMemRegionManager() const = 0; @@ -73,17 +72,25 @@ public: bool hasStackStorage() const; + bool hasParametersStorage() const; + + bool hasGlobalsStorage() const; + + bool hasGlobalsOrParametersStorage() const; + bool hasHeapStorage() const; bool hasHeapOrStackStorage() const; - virtual void print(llvm::raw_ostream& os) const; + virtual void print(llvm::raw_ostream& os) const; + + void printStdErr() const; Kind getKind() const { return kind; } template<typename RegionTy> const RegionTy* getAs() const; - virtual bool isBoundable() const { return true; } + virtual bool isBoundable() const { return false; } static bool classof(const MemRegion*) { return true; } }; @@ -104,8 +111,6 @@ protected: } public: - //RegionExtent getExtent() const { return UndefinedExtent(); } - void Profile(llvm::FoldingSetNodeID& ID) const; bool isBoundable() const { return false; } @@ -315,6 +320,8 @@ public: return Str->getType(); } + bool isBoundable() const { return false; } + void Profile(llvm::FoldingSetNodeID& ID) const { ProfileRegion(ID, Str, superRegion); } @@ -384,7 +391,9 @@ public: QualType getValueType(ASTContext& C) const { return C.getCanonicalType(CL->getType()); } - + + bool isBoundable() const { return !CL->isFileScope(); } + void Profile(llvm::FoldingSetNodeID& ID) const; void print(llvm::raw_ostream& os) const; @@ -584,15 +593,17 @@ class MemRegionManager { llvm::BumpPtrAllocator& A; llvm::FoldingSet<MemRegion> Regions; - MemSpaceRegion* globals; - MemSpaceRegion* stack; - MemSpaceRegion* heap; - MemSpaceRegion* unknown; - MemSpaceRegion* code; + MemSpaceRegion *globals; + MemSpaceRegion *stack; + MemSpaceRegion *stackArguments; + MemSpaceRegion *heap; + MemSpaceRegion *unknown; + MemSpaceRegion *code; public: MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator& a) - : C(c), A(a), globals(0), stack(0), heap(0), unknown(0), code(0) {} + : C(c), A(a), globals(0), stack(0), stackArguments(0), heap(0), + unknown(0), code(0) {} ~MemRegionManager() {} @@ -600,24 +611,28 @@ public: /// getStackRegion - Retrieve the memory region associated with the /// current stack frame. - MemSpaceRegion* getStackRegion(); + MemSpaceRegion *getStackRegion(); + + /// getStackArgumentsRegion - Retrieve the memory region associated with + /// function/method arguments of the current stack frame. + MemSpaceRegion *getStackArgumentsRegion(); /// getGlobalsRegion - Retrieve the memory region associated with /// all global variables. - MemSpaceRegion* getGlobalsRegion(); + MemSpaceRegion *getGlobalsRegion(); /// getHeapRegion - Retrieve the memory region associated with the /// generic "heap". - MemSpaceRegion* getHeapRegion(); + MemSpaceRegion *getHeapRegion(); /// getUnknownRegion - Retrieve the memory region associated with unknown /// memory space. - MemSpaceRegion* getUnknownRegion(); + MemSpaceRegion *getUnknownRegion(); - MemSpaceRegion* getCodeRegion(); + MemSpaceRegion *getCodeRegion(); /// getAllocaRegion - Retrieve a region associated with a call to alloca(). - AllocaRegion* getAllocaRegion(const Expr* Ex, unsigned Cnt); + AllocaRegion *getAllocaRegion(const Expr* Ex, unsigned Cnt); /// getCompoundLiteralRegion - Retrieve the region associated with a /// given CompoundLiteral. @@ -785,8 +800,12 @@ template <> struct MemRegionManagerTrait<VarRegion> { typedef MemRegion SuperRegionTy; static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr, const VarDecl *d) { - return d->hasLocalStorage() ? MRMgr.getStackRegion() - : MRMgr.getGlobalsRegion(); + if (d->hasLocalStorage()) { + return isa<ParmVarDecl>(d) || isa<ImplicitParamDecl>(d) + ? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion(); + } + + return MRMgr.getGlobalsRegion(); } }; diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h index 36137fb117b36..4bc5e27aacf05 100644 --- a/include/clang/Analysis/PathSensitive/SVals.h +++ b/include/clang/Analysis/PathSensitive/SVals.h @@ -110,6 +110,8 @@ public: /// getAsSymbolicExpression - If this Sval wraps a symbolic expression then /// return that expression. Otherwise return NULL. const SymExpr *getAsSymbolicExpression() const; + + const MemRegion *getAsRegion() const; void print(llvm::raw_ostream& OS) const; void printStdErr() const; diff --git a/include/clang/Analysis/PathSensitive/ValueManager.h b/include/clang/Analysis/PathSensitive/ValueManager.h index de318a0f03e8f..36d1df2150df9 100644 --- a/include/clang/Analysis/PathSensitive/ValueManager.h +++ b/include/clang/Analysis/PathSensitive/ValueManager.h @@ -67,12 +67,17 @@ public: const void* SymbolTag = 0) { return SymMgr.getConjuredSymbol(E, VisitCount, SymbolTag); } - + /// makeZeroVal - Construct an SVal representing '0' for the specified type. SVal makeZeroVal(QualType T); - /// GetRegionValueSymbolVal - make a unique symbol for value of R. - SVal getRegionValueSymbolVal(const MemRegion* R, QualType T = QualType()); + /// getRegionValueSymbolVal - make a unique symbol for value of R. + SVal getRegionValueSymbolVal(const MemRegion *R, QualType T = QualType()); + + SVal getRegionValueSymbolValOrUnknown(const MemRegion *R, QualType T) { + return SymMgr.canSymbolicate(T) ? getRegionValueSymbolVal(R, T) + : UnknownVal(); + } SVal getConjuredSymbolVal(const Expr *E, unsigned Count); SVal getConjuredSymbolVal(const Expr* E, QualType T, unsigned Count); |