aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-07-10 21:24:45 +0000
committerTed Kremenek <kremenek@apple.com>2009-07-10 21:24:45 +0000
commit8d344ae81aeae1f2e4f21eddd1021acdca85abd7 (patch)
tree27f809569abe0d395e6334d874b5b363e896ba77
parent3f9811b46abcbb34c76d0e742dd31f899312d2bf (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75285 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/Store.cpp28
-rw-r--r--test/Analysis/misc-ps.m17
2 files changed, 13 insertions, 32 deletions
diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp
index ad6bd7e4f6..7101b34477 100644
--- a/lib/Analysis/Store.cpp
+++ b/lib/Analysis/Store.cpp
@@ -45,24 +45,6 @@ static bool IsCompleteType(ASTContext &Ctx, QualType Ty) {
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 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R,
// 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 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R,
}
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;
}
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index 19d7622805..a0da13e0aa 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -324,17 +324,20 @@ void test_rdar_7034511(NSArray *y) {
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);
}