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

Ted Kremenek kremenek at apple.com
Fri Jul 10 14:24:45 PDT 2009


Author: kremenek
Date: Fri Jul 10 16:24:45 2009
New Revision: 75285

URL: http://llvm.org/viewvc/llvm-project?rev=75285&view=rev
Log:
Revert r75281 and simply remove the assertion in NewCastRegion that
CodeTextRegions can only be casted to FunctionPointer or BlockPointerTypes. This
simply isn't true. We can handle bogus operations on CodeTextRegions (e.g, an
array access) elsewhere.

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=75285&r1=75284&r2=75285&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Fri Jul 10 16:24:45 2009
@@ -45,24 +45,6 @@
   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) {
@@ -82,10 +64,6 @@
   // 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:
@@ -99,9 +77,9 @@
     }
       
     case MemRegion::CodeTextRegionKind: {
-      // CodeTextRegion should be cast to only function pointer type.
-      assert(CastToTy->isFunctionPointerType() || 
-             CastToTy->isBlockPointerType());
+      // CodeTextRegion should be cast to only function pointer type, although
+      // they can in practice be casted to anything, e.g, void*, char*, etc.
+      // Just pass the region through.
       break;
     }
       

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

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Fri Jul 10 16:24:45 2009
@@ -324,17 +324,20 @@
   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() {
+// Handle casts of function pointers (CodeTextRegions) to arbitrary pointer
+// types. This was previously causing a crash in CastRegion.
+void handle_funcptr_voidptr_casts() {
   void **ptr;
   typedef void *PVOID;
+  typedef void *PCHAR;  
   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);
+  FARPROC handle_funcptr_voidptr_casts_aux();
+  PVOID handle_funcptr_voidptr_casts_aux_2(PVOID volatile *x);
+  PVOID handle_funcptr_voidptr_casts_aux_3(PCHAR volatile *x);  
   
-  ptr = (void**) handle_higher_order_voidptr_casts_aux();
-  handle_higher_order_voidptr_casts_aux_2(ptr);
+  ptr = (void**) handle_funcptr_voidptr_casts_aux();
+  handle_funcptr_voidptr_casts_aux_2(ptr);
+  handle_funcptr_voidptr_casts_aux_3(ptr);
 }
 





More information about the cfe-commits mailing list