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) {
// 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:
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;
}
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);
+}
+