]> granicus.if.org Git - clang/commitdiff
Re-apply 68028. The code had drifted enough that the tests would fail without
authorTed Kremenek <kremenek@apple.com>
Mon, 30 Mar 2009 22:20:54 +0000 (22:20 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 30 Mar 2009 22:20:54 +0000 (22:20 +0000)
it.  Will discuss offline whether symbolic regions should by typed or typeless.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68070 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/MemRegion.h
lib/Analysis/MemRegion.cpp
lib/Analysis/RegionStore.cpp

index b54efadd3a3254dbe9ca63538d1f79fd2c1b0b7a..766c0918d1c63194da82b948f4e70f35be139f4f 100644 (file)
@@ -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);
index 738e8c67d69346a2e9ffd9cf9183a3eb54699ab7..7c13f0701e7e4a374458c031352ee25a32cc3bad 100644 (file)
@@ -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();
index 60948062f6f9f54db3f9ba05668da9edaa0bae34..0b2d99b29b13b63c4780a1cf5ff9b925702b8d40 100644 (file)
@@ -362,9 +362,13 @@ SVal RegionStoreManager::getLValueFieldOrIvar(const GRState* St, SVal Base,
     BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
     break;
 
-  case loc::SymbolValKind:
-    BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol());
+  case loc::SymbolValKind: {
+    SymbolRef Sym = cast<loc::SymbolVal>(&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<loc::SymbolVal>(Base)
-               ? MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(Base).getSymbol())
-               : cast<TypedRegion>(cast<loc::MemRegionVal>(Base).getRegion());
+  if (isa<loc::SymbolVal>(Base)) {
+    SymbolRef Sym = cast<loc::SymbolVal>(Base).getSymbol();
+    SymbolicRegion* SR = MRMgr.getSymbolicRegion(Sym);
+    // Layer the type information.
+    BaseRegion = MRMgr.getTypedViewRegion(Sym->getType(getContext()), SR);
+  } 
+  else
+    BaseRegion = cast<TypedRegion>(cast<loc::MemRegionVal>(Base).getRegion());
 
   // Pointer of any type can be cast and used as array base.
   const ElementRegion *ElemR = dyn_cast<ElementRegion>(BaseRegion);