case CastExpr::CK_IntegralToPointer: {
Value *Src = Visit(const_cast<Expr*>(E));
-
+
// First, convert to the correct width so that we control the kind of
// extension.
const llvm::Type *MiddleTy = CGF.IntPtrTy;
bool InputSigned = E->getType()->isSignedIntegerType();
llvm::Value* IntResult =
Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
-
+
return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy));
}
case CastExpr::CK_PointerToIntegral: {
Value *Src = Visit(const_cast<Expr*>(E));
+
+ // Handle conversion to bool correctly.
+ if (DestTy->isBooleanType())
+ return EmitScalarConversion(Visit(E), E->getType(), DestTy);
+
return Builder.CreatePtrToInt(Src, ConvertType(DestTy));
}
case CastExpr::CK_ToVoid: {
--- /dev/null
+// RUN: %clang_cc1 -triple i386 -emit-llvm -O2 -o - %s | FileCheck %s
+
+// CHECK: define i32 @f0()
+// CHECK: ret i32 1
+// CHECK: }
+
+static _Bool f0_0(void *a0) { return (_Bool) a0; }
+int f0() { return f0_0((void*) 0x2); }