[cfe-commits] r75281 - in /cfe/trunk: lib/Analysis/Store.cpp test/Analysis/misc-ps.m

Ted Kremenek kremenek at apple.com
Fri Jul 10 14:11:16 PDT 2009


Author: kremenek
Date: Fri Jul 10 16:11:16 2009
New Revision: 75281

URL: http://llvm.org/viewvc/llvm-project?rev=75281&view=rev
Log:
Fix crash in StoreManager::NewCastRegion regarding handling casts to void*,
void**, void***, etc.  Such casts should just pass the region through.

Modified:
    cfe/trunk/lib/Analysis/Store.cpp
    cfe/trunk/test/Analysis/misc-ps.m

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

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Fri Jul 10 16:11:16 2009
@@ -45,6 +45,24 @@
   return true;
 }
 
+static bool isVoidOrHigherOrderVoidPtr(ASTContext &Ctx, QualType Ty) {
+  while (true) {
+    Ty = Ctx.getCanonicalType(Ty);
+    
+    if (Ty->isVoidType())
+      return true;    
+
+    if (const PointerType *PT = Ty->getAsPointerType()) {
+      Ty = PT->getPointeeType();
+      continue;
+    }
+    
+    break;
+  }
+  
+  return false;
+}
+
 StoreManager::CastResult
 StoreManager::NewCastRegion(const GRState *state, const MemRegion* R,
                             QualType CastToTy) {
@@ -64,6 +82,10 @@
   // already be handled.
   QualType PointeeTy = CastToTy->getAsPointerType()->getPointeeType();
   
+  // Casts to 'void*', 'void**', 'void***', etc., should just pass through.
+  if (isVoidOrHigherOrderVoidPtr(Ctx, PointeeTy))
+    return CastResult(state, R);
+  
   // Process region cast according to the kind of the region being cast.
   switch (R->getKind()) {
     case MemRegion::BEG_TYPED_REGIONS:
@@ -78,9 +100,8 @@
       
     case MemRegion::CodeTextRegionKind: {
       // CodeTextRegion should be cast to only function pointer type.
-      assert(CastToTy->isFunctionPointerType() || CastToTy->isBlockPointerType()
-             || (CastToTy->isPointerType() &&
-                 CastToTy->getAsPointerType()->getPointeeType()->isVoidType()));
+      assert(CastToTy->isFunctionPointerType() || 
+             CastToTy->isBlockPointerType());
       break;
     }
       

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=75281&r1=75280&r2=75281&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Fri Jul 10 16:11:16 2009
@@ -324,3 +324,17 @@
   if (x == ((void*) 0)) {}
 }
 
+// Handle arbitrary void*^n -> void*^m casts.  This was previously causing
+// a crash in CastRegion.
+void handle_higher_order_voidptr_casts() {
+  void **ptr;
+  typedef void *PVOID;
+  typedef long INT_PTR, *PINT_PTR;
+  typedef INT_PTR (*FARPROC)();
+  FARPROC handle_higher_order_voidptr_casts_aux();
+  PVOID handle_higher_order_voidptr_casts_aux_2(PVOID volatile *x);
+  
+  ptr = (void**) handle_higher_order_voidptr_casts_aux();
+  handle_higher_order_voidptr_casts_aux_2(ptr);
+}
+





More information about the cfe-commits mailing list