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 | ead6824c3cdab8d832648a16ea123ea1554d39b6 (patch) | |
tree | 939b7e6aeb07f4d571e2ae92b142c96284af9beb /clang/lib/CodeGen/CGExprScalar.cpp | |
parent | 0770d25758cad7806cda2c53e132b8906461f951 (diff) | |
download | bcm5719-llvm-ead6824c3cdab8d832648a16ea123ea1554d39b6.tar.gz bcm5719-llvm-ead6824c3cdab8d832648a16ea123ea1554d39b6.zip |
IRgen: Fix a horrible bug in pointer to bool conversion, which we were treating
as a truncation not a comparison to null.
llvm-svn: 112021
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 49deb7b365a..6901f9b924f 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/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: { |