[cfe-commits] r69751 - /cfe/trunk/lib/Analysis/Store.cpp

Ted Kremenek kremenek at apple.com
Tue Apr 21 16:31:46 PDT 2009


Author: kremenek
Date: Tue Apr 21 18:31:46 2009
New Revision: 69751

URL: http://llvm.org/viewvc/llvm-project?rev=69751&view=rev
Log:
This patch is largely due to Zhongxing Xu. I've simply applied it because of
some refactoring I did recently to StoreManager.

StoreManager::CastRegion: Handle casts to void* by stripping TypedViewRegions.

Modified:
    cfe/trunk/lib/Analysis/Store.cpp

Modified: cfe/trunk/lib/Analysis/Store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Store.cpp?rev=69751&r1=69750&r2=69751&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Tue Apr 21 18:31:46 2009
@@ -25,23 +25,43 @@
 StoreManager::CastRegion(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)) {
-    ASTContext& Ctx = StateMgr.getContext();
     QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx));
-    QualType Tb = Ctx.getCanonicalType(CastToTy);
-    
-    if (Ta == Tb)
+
+    if (Ta == ToTy)
       return CastResult(state, R);
   }
   
-  // FIXME: We should handle the case when we are casting *back* to a
-  // previous type. For example:
-  //
-  //      void* x = ...;
-  //      char* y = (char*) x;
-  //      void* z = (void*) y; // <-- we should get the same region that is 
-  //                                  bound to 'x'
+  // Check if we are casting to 'void*'.
+  // FIXME: Handle arbitrary upcasts.
+  if (const PointerType* PTy = dyn_cast<PointerType>(ToTy.getTypePtr()))
+    if (PTy->getPointeeType()->isVoidType()) {
+
+      // Casts to void* only removes TypedViewRegion. If there is no
+      // TypedViewRegion, leave the region untouched. This happens when:
+      //
+      // void foo(void*);
+      // ...
+      // void bar() {
+      //   int x;
+      //   foo(&x);
+      // }
+
+      if (const TypedViewRegion *TR = dyn_cast<TypedViewRegion>(R))
+        R = TR->removeViews();
+      
+      return CastResult(state, R);
+    }
+
+  // FIXME: We don't want to layer region views.  Need to handle
+  // arbitrary downcasts.
+
   const MemRegion* ViewR = MRMgr.getTypedViewRegion(CastToTy, R);  
   return CastResult(AddRegionView(state, ViewR, R), ViewR);
 }





More information about the cfe-commits mailing list