diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-08-25 03:32:38 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-08-25 03:32:38 +0000 |
commit | 89f176d89aefe8a23bbf0ace9b329562f4970d5f (patch) | |
tree | 918d42b6d0906c29394b4a3ba3976ac9e5bd21f3 /lib/CodeGen/CGExprScalar.cpp | |
parent | a8f28da6265950eea768f7e4ade15e4ebaddd56f (diff) |
IRgen: Fix a horrible bug in pointer to bool conversion, which we were treating
as a truncation not a comparison to null.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112021 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 49deb7b365..6901f9b924 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1017,18 +1017,23 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { 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: { |