]> granicus.if.org Git - clang/commitdiff
Added the notion of a "boundable region", which is a region that can have a direct...
authorTed Kremenek <kremenek@apple.com>
Wed, 4 Mar 2009 02:43:08 +0000 (02:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 4 Mar 2009 02:43:08 +0000 (02:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66005 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/GRState.h
include/clang/Analysis/PathSensitive/MemRegion.h
lib/Analysis/CFRefCount.cpp
lib/Analysis/MemRegion.cpp

index b3f4dea86088272604e8f337ae150843219aa961..9c30aa631d7d7c2daf84e93bb160313f31dbb34b 100644 (file)
@@ -488,6 +488,12 @@ public:
   }  
 
   SVal GetSValAsScalarOrLoc(const GRState* state, const MemRegion *R) {
+    // We only want to do fetches from regions that we can actually bind
+    // values.  For example, SymbolicRegions of type 'id<...>' cannot
+    // have direct bindings (but their can be bindings on their subregions).
+    if (!R->isBoundable(getContext()))
+      return UnknownVal();
+    
     if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
       QualType T = TR->getRValueType(getContext());
       if (Loc::IsLocType(T) || T->isIntegerType())
index cd7011e53ad1736b34f8be101208693aa48a6d23..743a3b909880c5aa3b105704c2d3c437ad864dcb 100644 (file)
@@ -69,6 +69,8 @@ public:
   virtual void print(llvm::raw_ostream& os) const;  
   
   Kind getKind() const { return kind; }  
+  
+  virtual bool isBoundable(ASTContext&) const { return true; }
 
   static bool classof(const MemRegion*) { return true; }
 };
@@ -84,6 +86,8 @@ public:
 
   void Profile(llvm::FoldingSetNodeID& ID) const;
 
+  bool isBoundable(ASTContext &) const { return false; }
+
   static bool classof(const MemRegion* R) {
     return R->getKind() == MemSpaceRegionKind;
   }
@@ -156,6 +160,13 @@ public:
   QualType getDesugaredLValueType(ASTContext& C) const {
     return getLValueType(C)->getDesugaredType();
   }
+  
+  bool isBoundable(ASTContext &C) const {
+    // FIXME: This needs to be adjusted for structures and arrays.
+    // All this will reject right now is ObjCQualifiedIdType and
+    // BlockPointerType.
+    return getLValueType(C)->isPointerType();
+  }
 
   static bool classof(const MemRegion* R) {
     unsigned k = R->getKind();
@@ -182,6 +193,7 @@ public:
   }
 
   QualType getRValueType(ASTContext& C) const;
+  QualType getLValueType(ASTContext& C) const;
 
   void Profile(llvm::FoldingSetNodeID& ID) const;
 
index 13805dc5de9de530992bda2a4b3bc5284c698cbc..5e1857168dc0036bebfa5f7f035f10ba5bcadd10 100644 (file)
@@ -1650,7 +1650,7 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
           R = dyn_cast<TypedRegion>(ATR->getSuperRegion());
         }
         
-        if (R) {          
+        if (R && R->isBoundable(Ctx)) {          
           // Is the invalidated variable something that we were tracking?
           SymbolRef Sym = state.GetSValAsScalarOrLoc(R).getAsLocSymbol();
           if (Sym.isValid())
index f78d937df82ebde55802c4cc8657890213a418c4..8dd31b54b0baf8dd78684fcfeda9f9483319b352 100644 (file)
@@ -117,12 +117,22 @@ QualType SymbolicRegion::getRValueType(ASTContext& C) const {
   // Get the type of the symbol.
   QualType T = data.getType(C);
 
-  // Only when the symbol has pointer type it can have a symbolic region
-  // associated with it.
-  PointerType* PTy = cast<PointerType>(T.getTypePtr()->getDesugaredType());
+  if (const PointerType* PTy = T->getAsPointerType())
+    return PTy->getPointeeType();
+    
+  if (const BlockPointerType* PTy = T->getAsBlockPointerType())
+    return PTy->getPointeeType();
 
-  // The type of the symbolic region is the pointee type of the symbol.
-  return PTy->getPointeeType();
+  assert(!T->getAsObjCQualifiedIdType() &&
+         "There is no rvalue type for id<...>");  
+  
+  assert(Loc::IsLocType(T) && "Non-location type.");
+  return QualType();
+}
+
+QualType SymbolicRegion::getLValueType(ASTContext& C) const {
+  const SymbolData& data = SymMgr.getSymbolData(sym);
+  return data.getType(C);
 }
 
 QualType ElementRegion::getRValueType(ASTContext& C) const {
@@ -161,7 +171,7 @@ void AllocaRegion::print(llvm::raw_ostream& os) const {
 }
 
 void TypedViewRegion::print(llvm::raw_ostream& os) const {
-  os << "anon_type{" << T.getAsString() << ',';
+  os << "typed_view{" << T.getAsString() << ',';
   getSuperRegion()->print(os);
   os << '}';
 }