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

Ted Kremenek kremenek at apple.com
Fri Jul 17 23:27:52 PDT 2009


Author: kremenek
Date: Sat Jul 18 01:27:51 2009
New Revision: 76288

URL: http://llvm.org/viewvc/llvm-project?rev=76288&view=rev
Log:
Fix crash in StoreManager::NewCastRegion() when handling casts from 'id' (or whatever) to a BlockPointerType.

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=76288&r1=76287&r2=76288&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Sat Jul 18 01:27:51 2009
@@ -59,6 +59,23 @@
     state = setCastType(state, R, CastToTy);
     return CastResult(state, R);
   }
+  
+  if (CastToTy->isBlockPointerType()) {
+    if (isa<CodeTextRegion>(R))
+      return CastResult(state, R);
+    
+    // FIXME: This may not be the right approach, depending on the symbol
+    // involved.  Blocks can be casted to/from 'id', as they can be treated
+    // as Objective-C objects.
+    if (SymbolRef sym = loc::MemRegionVal(R).getAsSymbol()) {
+      R = MRMgr.getCodeTextRegion(sym, CastToTy);
+      return CastResult(state, R);
+    }
+
+    // We don't know what to make of it.  Return a NULL region, which
+    // will be interpretted as UnknownVal.
+    return CastResult(state, NULL);
+  }
 
   // Now assume we are casting from pointer to pointer. Other cases should
   // already be handled.
@@ -77,8 +94,9 @@
     }
       
     case MemRegion::CodeTextRegionKind: {
-      // CodeTextRegion should be cast to only function pointer type, although
-      // they can in practice be casted to anything, e.g, void*, char*, etc.
+      // CodeTextRegion should be cast to only a function or block 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=76288&r1=76287&r2=76288&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Sat Jul 18 01:27:51 2009
@@ -430,3 +430,10 @@
   return p[i+1];
 }
 
+// This case tests that CastRegion handles casts involving BlockPointerTypes.
+// It should not crash.
+void test_block_cast() {
+  id test_block_cast_aux();
+  (void (^)(void *))test_block_cast_aux(); // expected-warning{{expression result unused}}
+}
+





More information about the cfe-commits mailing list