From a45fec1a586a3b234d301bb89e26f2e891def0d7 Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Mon, 30 Mar 2009 06:48:56 +0000 Subject: [PATCH] Make SymbolicRegion untyped. Layer the type information with a TypedViewRegion on top of the SymbolicRegion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68028 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/Analysis/PathSensitive/MemRegion.h | 9 +++----- lib/Analysis/MemRegion.cpp | 22 ------------------- lib/Analysis/RegionStore.cpp | 19 +++++++++++----- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index b54efadd3a..766c0918d1 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -39,10 +39,10 @@ class MemRegionManager; class MemRegion : public llvm::FoldingSetNode { public: enum Kind { MemSpaceRegionKind, + SymbolicRegionKind, AllocaRegionKind, // Typed regions. BEG_TYPED_REGIONS, - SymbolicRegionKind, CompoundLiteralRegionKind, StringRegionKind, ElementRegionKind, TypedViewRegionKind, @@ -179,21 +179,18 @@ public: /// either a real region, a NULL pointer, etc. It essentially is used to /// map the concept of symbolic values into the domain of regions. Symbolic /// regions do not need to be typed. -class SymbolicRegion : public TypedRegion { +class SymbolicRegion : public SubRegion { protected: const SymbolRef sym; public: SymbolicRegion(const SymbolRef s, const MemRegion* sreg) - : TypedRegion(sreg, SymbolicRegionKind), sym(s) {} + : SubRegion(sreg, SymbolicRegionKind), sym(s) {} SymbolRef getSymbol() const { return sym; } - QualType getRValueType(ASTContext& C) const; - QualType getLValueType(ASTContext& C) const; - void Profile(llvm::FoldingSetNodeID& ID) const; static void ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym); diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 738e8c67d6..7c13f0701e 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -111,28 +111,6 @@ void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const { // getLValueType() and getRValueType() //===----------------------------------------------------------------------===// -QualType SymbolicRegion::getRValueType(ASTContext& C) const { - // Get the type of the symbol. - QualType T = sym->getType(C); - - if (const PointerType* PTy = T->getAsPointerType()) - return PTy->getPointeeType(); - - if (const BlockPointerType* PTy = T->getAsBlockPointerType()) - return PTy->getPointeeType(); - - // There is no rvalue type of id<...>. - if (T->getAsObjCQualifiedIdType()) - return QualType(); - - assert(Loc::IsLocType(T) && "Non-location type."); - return QualType(); -} - -QualType SymbolicRegion::getLValueType(ASTContext& C) const { - return sym->getType(C); -} - QualType ElementRegion::getRValueType(ASTContext& C) const { // Strip off typedefs from the ArrayRegion's RvalueType. QualType T = getArrayRegion()->getRValueType(C)->getDesugaredType(); diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 60948062f6..0b2d99b29b 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -362,9 +362,13 @@ SVal RegionStoreManager::getLValueFieldOrIvar(const GRState* St, SVal Base, BaseR = cast(BaseL).getRegion(); break; - case loc::SymbolValKind: - BaseR = MRMgr.getSymbolicRegion(cast(&BaseL)->getSymbol()); + case loc::SymbolValKind: { + SymbolRef Sym = cast(&BaseL)->getSymbol(); + const SymbolicRegion* SR = MRMgr.getSymbolicRegion(Sym); + // Layer the type information. + BaseR = MRMgr.getTypedViewRegion(Sym->getType(getContext()), SR); break; + } case loc::GotoLabelKind: case loc::FuncValKind: @@ -407,9 +411,14 @@ SVal RegionStoreManager::getLValueElement(const GRState* St, const TypedRegion* BaseRegion = 0; - BaseRegion = isa(Base) - ? MRMgr.getSymbolicRegion(cast(Base).getSymbol()) - : cast(cast(Base).getRegion()); + if (isa(Base)) { + SymbolRef Sym = cast(Base).getSymbol(); + SymbolicRegion* SR = MRMgr.getSymbolicRegion(Sym); + // Layer the type information. + BaseRegion = MRMgr.getTypedViewRegion(Sym->getType(getContext()), SR); + } + else + BaseRegion = cast(cast(Base).getRegion()); // Pointer of any type can be cast and used as array base. const ElementRegion *ElemR = dyn_cast(BaseRegion); -- 2.40.0