}
void Verifier::visitConstantExpr(const ConstantExpr *CE) {
- if (CE->getOpcode() != Instruction::BitCast)
- return;
-
- Assert(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0),
- CE->getType()),
- "Invalid bitcast", CE);
+ if (CE->getOpcode() == Instruction::BitCast)
+ Assert(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0),
+ CE->getType()),
+ "Invalid bitcast", CE);
+
+ if (CE->getOpcode() == Instruction::IntToPtr ||
+ CE->getOpcode() == Instruction::PtrToInt) {
+ auto *PtrTy = CE->getOpcode() == Instruction::IntToPtr
+ ? CE->getType()
+ : CE->getOperand(0)->getType();
+ StringRef Msg = CE->getOpcode() == Instruction::IntToPtr
+ ? "inttoptr not supported for non-integral pointers"
+ : "ptrtoint not supported for non-integral pointers";
+ Assert(
+ !DL.isNonIntegralPointerType(cast<PointerType>(PtrTy->getScalarType())),
+ Msg);
+ }
}
bool Verifier::verifyAttributeCount(AttributeSet Attrs, unsigned Params) {
(i + 3 == e && isa<InvokeInst>(I)),
"Cannot take the address of an inline asm!", &I);
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
- if (CE->getType()->isPtrOrPtrVectorTy()) {
+ if (CE->getType()->isPtrOrPtrVectorTy() ||
+ !DL.getNonIntegralAddressSpaces().empty()) {
// If we have a ConstantExpr pointer, we need to see if it came from an
- // illegal bitcast (inttoptr <constant int> )
+ // illegal bitcast. If the datalayout string specifies non-integral
+ // address spaces then we also need to check for illegal ptrtoint and
+ // inttoptr expressions.
visitConstantExprsRecursively(CE);
}
}
%val = ptrtoint i8 addrspace(6)* %ptr to i64
ret i64 %val
}
+
+define i8 addrspace(4)* @f_7() {
+; CHECK: inttoptr not supported for non-integral pointers
+ ret i8 addrspace(4)* inttoptr (i64 50 to i8 addrspace(4)*)
+}
+
+@global0 = addrspace(4) constant i8 42
+
+define i64 @f_8() {
+; CHECK: ptrtoint not supported for non-integral pointers
+ ret i64 ptrtoint (i8 addrspace(4)* @global0 to i64)
+}