diff options
62 files changed, 20 insertions, 312 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index a65c71b5ec..3cfcc5cd5d 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -46,7 +46,6 @@ public: CodeTextRegionKind, CompoundLiteralRegionKind, StringRegionKind, ElementRegionKind, - TypedViewRegionKind, // Decl Regions. BEG_DECL_REGIONS, VarRegionKind, FieldRegionKind, @@ -340,46 +339,6 @@ public: } }; -class TypedViewRegion : public TypedRegion { - friend class MemRegionManager; - QualType LValueType; - - TypedViewRegion(QualType lvalueType, const MemRegion* sreg) - : TypedRegion(sreg, TypedViewRegionKind), LValueType(lvalueType) {} - - static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T, - const MemRegion* superRegion); - -public: - - void dumpToStream(llvm::raw_ostream& os) const; - - QualType getLocationType(ASTContext&) const { - return LValueType; - } - - QualType getValueType(ASTContext&) const { - const PointerType* PTy = LValueType->getAsPointerType(); - assert(PTy); - return PTy->getPointeeType(); - } - - bool isBoundable() const { - return isa<PointerType>(LValueType); - } - - void Profile(llvm::FoldingSetNodeID& ID) const { - ProfileRegion(ID, LValueType, superRegion); - } - - static bool classof(const MemRegion* R) { - return R->getKind() == TypedViewRegionKind; - } - - const MemRegion *removeViews() const; -}; - - /// CompoundLiteralRegion - A memory region representing a compound literal. /// Compound literals are essentially temporaries that are stack allocated /// or in the global constant pool. @@ -575,22 +534,10 @@ public: template<typename RegionTy> const RegionTy* MemRegion::getAs() const { - const MemRegion *R = this; - - do { - if (const RegionTy* RT = dyn_cast<RegionTy>(R)) - return RT; - - if (const TypedViewRegion *TR = dyn_cast<TypedViewRegion>(R)) { - R = TR->getSuperRegion(); - continue; - } - - break; - } - while (R); + if (const RegionTy* RT = dyn_cast<RegionTy>(this)) + return RT; - return 0; + return NULL; } //===----------------------------------------------------------------------===// @@ -680,10 +627,6 @@ public: /// object). ObjCIvarRegion* getObjCIvarRegion(const ObjCIvarDecl* ivd, const MemRegion* superRegion); - - TypedViewRegion* getTypedViewRegion(QualType LValueType, - const MemRegion* superRegion); - CodeTextRegion* getCodeTextRegion(SymbolRef sym, QualType t); CodeTextRegion* getCodeTextRegion(const FunctionDecl* fd, QualType t); diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h index c0409d06a1..c897b374a1 100644 --- a/include/clang/Analysis/PathSensitive/Store.h +++ b/include/clang/Analysis/PathSensitive/Store.h @@ -37,12 +37,11 @@ class StoreManager { protected: ValueManager &ValMgr; GRStateManager &StateMgr; - const bool UseNewCastRegion; /// MRMgr - Manages region objects associated with this StoreManager. MemRegionManager &MRMgr; - StoreManager(GRStateManager &stateMgr, bool useNewCastRegion = false); + StoreManager(GRStateManager &stateMgr); protected: virtual const GRState *AddRegionView(const GRState *state, @@ -135,10 +134,7 @@ public: /// a MemRegion* to a specific location type. 'R' is the region being /// casted and 'CastToTy' the result type of the cast. CastResult CastRegion(const GRState *state, const MemRegion *region, - QualType CastToTy) { - return UseNewCastRegion ? NewCastRegion(state, region, CastToTy) - : OldCastRegion(state, region, CastToTy); - } + QualType CastToTy); virtual const GRState *setCastType(const GRState *state, const MemRegion* R, QualType T) { @@ -203,12 +199,6 @@ public: private: CastResult MakeElementRegion(const GRState *state, const MemRegion *region, QualType pointeeTy, QualType castToTy); - - CastResult NewCastRegion(const GRState *state, const MemRegion *region, - QualType CastToTy); - - CastResult OldCastRegion(const GRState *state, const MemRegion *region, - QualType CastToTy); }; // FIXME: Do we still need this? @@ -229,7 +219,6 @@ public: // FIXME: Do we need to pass GRStateManager anymore? StoreManager *CreateBasicStoreManager(GRStateManager& StMgr); -StoreManager *CreateBasicStoreOldCastManager(GRStateManager& StMgr); StoreManager *CreateRegionStoreManager(GRStateManager& StMgr); StoreManager *CreateFieldsOnlyRegionStoreManager(GRStateManager& StMgr); diff --git a/include/clang/Frontend/Analyses.def b/include/clang/Frontend/Analyses.def index 8974998b89..173ed135fc 100644 --- a/include/clang/Frontend/Analyses.def +++ b/include/clang/Frontend/Analyses.def @@ -53,7 +53,6 @@ ANALYSIS(CheckerCFRef, "checker-cfref", #endif ANALYSIS_STORE(BasicStore, "basic", "Use basic analyzer store", CreateBasicStoreManager) -ANALYSIS_STORE(BasicStoreOldCast, "basic-old-cast", "Use basic analyzer store with the old CastRegion", CreateBasicStoreOldCastManager) ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store", CreateRegionStoreManager) #ifndef ANALYSIS_CONSTRAINTS diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index b84bdf4100..a898147102 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -38,10 +38,8 @@ class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager { const MemRegion* SelfRegion; public: - BasicStoreManager(GRStateManager& mgr, bool useNewCastRegion = true) - : StoreManager(mgr, useNewCastRegion), - VBFactory(mgr.getAllocator()), - SelfRegion(0) {} + BasicStoreManager(GRStateManager& mgr) + : StoreManager(mgr), VBFactory(mgr.getAllocator()), SelfRegion(0) {} ~BasicStoreManager() {} @@ -130,10 +128,6 @@ StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { return new BasicStoreManager(StMgr); } -StoreManager* clang::CreateBasicStoreOldCastManager(GRStateManager& StMgr) { - return new BasicStoreManager(StMgr, false); -} - SVal BasicStoreManager::getLValueVar(const GRState *state, const VarDecl* VD) { return ValMgr.makeLoc(MRMgr.getVarRegion(VD)); } diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index a708bd3068..3c174df282 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -74,13 +74,6 @@ void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const { ProfileRegion(ID, Ex, Cnt, superRegion); } -void TypedViewRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T, - const MemRegion* superRegion) { - ID.AddInteger((unsigned) TypedViewRegionKind); - ID.Add(T); - ID.AddPointer(superRegion); -} - void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const { CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion); } @@ -197,11 +190,6 @@ void SymbolicRegion::dumpToStream(llvm::raw_ostream& os) const { os << "SymRegion{" << sym << '}'; } -void TypedViewRegion::dumpToStream(llvm::raw_ostream& os) const { - os << "typed_view{" << LValueType.getAsString() << ',' - << getSuperRegion() << '}'; -} - void VarRegion::dumpToStream(llvm::raw_ostream& os) const { os << cast<VarDecl>(D)->getNameAsString(); } @@ -314,11 +302,6 @@ MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d, return getSubRegion<ObjCObjectRegion>(d, superRegion); } -TypedViewRegion* -MemRegionManager::getTypedViewRegion(QualType t, const MemRegion* superRegion) { - return getSubRegion<TypedViewRegion>(t, superRegion); -} - AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) { return getRegion<AllocaRegion>(E, cnt); } @@ -389,16 +372,6 @@ bool MemRegion::hasGlobalsOrParametersStorage() const { // View handling. //===----------------------------------------------------------------------===// -const MemRegion *TypedViewRegion::removeViews() const { - const SubRegion *SR = this; - const MemRegion *R = SR; - while (SR && isa<TypedViewRegion>(SR)) { - R = SR->getSuperRegion(); - SR = dyn_cast<SubRegion>(R); - } - return R; -} - const MemRegion *MemRegion::getBaseRegion() const { const MemRegion *R = this; while (true) { diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index c533a7ec07..ccfbb27ccf 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -170,7 +170,7 @@ class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager { public: RegionStoreManager(GRStateManager& mgr, const RegionStoreFeatures &f) - : StoreManager(mgr, true), + : StoreManager(mgr), Features(f), RBFactory(mgr.getAllocator()), RVFactory(mgr.getAllocator()), @@ -679,10 +679,6 @@ SVal RegionStoreManager::getSizeInElements(const GRState *state, return ValMgr.makeIntVal(Str->getByteLength()+1, false); } - // TypedViewRegion will soon be removed. - case MemRegion::TypedViewRegionKind: - return UnknownVal(); - case MemRegion::VarRegionKind: { const VarRegion* VR = cast<VarRegion>(R); // Get the type of the variable. @@ -823,10 +819,6 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, case MemRegion::ObjCIvarRegionKind: return UnknownVal(); - // TypedViewRegion will soon be removed. - case MemRegion::TypedViewRegionKind: - return UnknownVal(); - case MemRegion::CodeTextRegionKind: // Technically this can happen if people do funny things with casts. return UnknownVal(); diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index 6f480e8d46..5ac18a1506 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -73,21 +73,10 @@ const FunctionDecl* SVal::getAsFunctionDecl() const { SymbolRef SVal::getAsLocSymbol() const { if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) { const MemRegion *R = X->getBaseRegion(); - - while (R) { - // Blast through region views. - if (const TypedViewRegion *View = dyn_cast<TypedViewRegion>(R)) { - R = View->getSuperRegion(); - continue; - } - if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) - return SymR->getSymbol(); - - break; - } + if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) + return SymR->getSymbol(); } - - return 0; + return NULL; } /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef. diff --git a/lib/Analysis/SValuator.cpp b/lib/Analysis/SValuator.cpp index 787c926f6b..079481a62a 100644 --- a/lib/Analysis/SValuator.cpp +++ b/lib/Analysis/SValuator.cpp @@ -73,10 +73,6 @@ SValuator::CastResult SValuator::EvalCast(SVal val, const GRState *state, // Check for casts from a region to a specific type. if (const MemRegion *R = val.getAsRegion()) { - // FIXME: For TypedViewRegions, we should handle the case where the - // underlying symbolic pointer is a function pointer or - // block pointer. - // FIXME: We should handle the case where we strip off view layers to get // to a desugared type. diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp index 114942177c..4341abdc72 100644 --- a/lib/Analysis/Store.cpp +++ b/lib/Analysis/Store.cpp @@ -16,10 +16,8 @@ using namespace clang; -StoreManager::StoreManager(GRStateManager &stateMgr, bool useNewCastRegion) - : ValMgr(stateMgr.getValueManager()), - StateMgr(stateMgr), - UseNewCastRegion(useNewCastRegion), +StoreManager::StoreManager(GRStateManager &stateMgr) + : ValMgr(stateMgr.getValueManager()), StateMgr(stateMgr), MRMgr(ValMgr.getRegionManager()) {} StoreManager::CastResult @@ -46,8 +44,8 @@ static bool IsCompleteType(ASTContext &Ctx, QualType Ty) { } StoreManager::CastResult -StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, - QualType CastToTy) { +StoreManager::CastRegion(const GRState *state, const MemRegion* R, + QualType CastToTy) { ASTContext& Ctx = StateMgr.getContext(); @@ -87,8 +85,7 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, case MemRegion::MemSpaceRegionKind: case MemRegion::BEG_DECL_REGIONS: case MemRegion::END_DECL_REGIONS: - case MemRegion::END_TYPED_REGIONS: - case MemRegion::TypedViewRegionKind: { + case MemRegion::END_TYPED_REGIONS: { assert(0 && "Invalid region cast"); break; } @@ -147,90 +144,3 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, return CastResult(state, R); } - - -StoreManager::CastResult -StoreManager::OldCastRegion(const GRState* state, const MemRegion* R, - QualType CastToTy) { - - ASTContext& Ctx = StateMgr.getContext(); - - // We need to know the real type of CastToTy. - QualType ToTy = Ctx.getCanonicalType(CastToTy); - - // Return the same region if the region types are compatible. - if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) { - QualType Ta = Ctx.getCanonicalType(TR->getLocationType(Ctx)); - - if (Ta == ToTy) - return CastResult(state, R); - } - - if (const PointerType* PTy = dyn_cast<PointerType>(ToTy.getTypePtr())) { - // Check if we are casting to 'void*'. - // FIXME: Handle arbitrary upcasts. - QualType Pointee = PTy->getPointeeType(); - if (Pointee->isVoidType()) { - while (true) { - if (const TypedViewRegion *TR = dyn_cast<TypedViewRegion>(R)) { - // Casts to void* removes TypedViewRegion. This happens when: - // - // void foo(void*); - // ... - // void bar() { - // int x; - // foo(&x); - // } - // - R = TR->removeViews(); - continue; - } - else if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { - // Casts to void* also removes ElementRegions. This happens when: - // - // void foo(void*); - // ... - // void bar() { - // int x; - // foo((char*)&x); - // } - // - R = ER->getSuperRegion(); - continue; - } - - break; - } - - return CastResult(state, R); - } - else if (Pointee->isIntegerType()) { - // FIXME: At some point, it stands to reason that this 'dyn_cast' should - // become a 'cast' and that 'R' will always be a TypedRegion. - if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) { - // Check if we are casting to a region with an integer type. We now - // the types aren't the same, so we construct an ElementRegion. - SVal Idx = ValMgr.makeZeroArrayIndex(); - - // If the super region is an element region, strip it away. - // FIXME: Is this the right thing to do in all cases? - const MemRegion *Base = isa<ElementRegion>(TR) ? TR->getSuperRegion() - : TR; - ElementRegion* ER = MRMgr.getElementRegion(Pointee, Idx, Base, - StateMgr.getContext()); - return CastResult(state, ER); - } - } - } - - // FIXME: Need to handle arbitrary downcasts. - // FIXME: Handle the case where a TypedViewRegion (layering a SymbolicRegion - // or an AllocaRegion is cast to another view, thus causing the memory - // to be re-used for a different purpose. - if (isa<SymbolicRegion>(R) || isa<AllocaRegion>(R)) { - const MemRegion* ViewR = MRMgr.getTypedViewRegion(CastToTy, R); - return CastResult(AddRegionView(state, ViewR, R), ViewR); - } - - return CastResult(state, R); -} diff --git a/test/Analysis/CFDateGC.m b/test/Analysis/CFDateGC.m index 240089ea57..557e7e8f91 100644 --- a/test/Analysis/CFDateGC.m +++ b/test/Analysis/CFDateGC.m @@ -1,9 +1,6 @@ // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=basic %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -verify -fobjc-gc -analyzer-constraints=basic %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify -fobjc-gc -analyzer-constraints=range %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -verify -fobjc-gc -analyzer-constraints=range %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify -fobjc-gc -disable-free %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -verify -fobjc-gc -disable-free %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -fobjc-gc %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -fobjc-gc %s diff --git a/test/Analysis/CFNumber.c b/test/Analysis/CFNumber.c index 9cabf8650b..f62d2ab569 100644 --- a/test/Analysis/CFNumber.c +++ b/test/Analysis/CFNumber.c @@ -1,7 +1,5 @@ // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify -triple x86_64-apple-darwin9 %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s diff --git a/test/Analysis/CFRetainRelease_NSAssertionHandler.m b/test/Analysis/CFRetainRelease_NSAssertionHandler.m index 2191b7fbde..1ff950725c 100644 --- a/test/Analysis/CFRetainRelease_NSAssertionHandler.m +++ b/test/Analysis/CFRetainRelease_NSAssertionHandler.m @@ -1,7 +1,5 @@ // RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic && -// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic-old-cast && // RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic && -// RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic-old-cast && // RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=region && // RUN: clang-cc -analyze -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=region diff --git a/test/Analysis/CGColorSpace.c b/test/Analysis/CGColorSpace.c index 10b5150cd9..2887d47c51 100644 --- a/test/Analysis/CGColorSpace.c +++ b/test/Analysis/CGColorSpace.c @@ -1,7 +1,5 @@ // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -analyzer-constraints=basic -verify %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s && -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic-old-cast -analyzer-constraints=range -verify %s && // RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s && // RUN: clang-cc -analyze -checker-cfr |