[llvm-branch-commits] [cfe-branch] r112510 - in /cfe/branches/Apple/williamson: lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CGExprScalar.cpp.orig test/CodeGen/_Bool-conversion.c
Daniel Dunbar
daniel at zuster.org
Mon Aug 30 13:20:12 PDT 2010
Author: ddunbar
Date: Mon Aug 30 15:20:12 2010
New Revision: 112510
URL: http://llvm.org/viewvc/llvm-project?rev=112510&view=rev
Log:
Merge r112021:
--
Author: Daniel Dunbar <daniel at zuster.org>
Date: Wed Aug 25 03:32:38 2010 +0000
IRgen: Fix a horrible bug in pointer to bool conversion, which we were treating
as a truncation not a comparison to null.
Added:
cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp.orig
- copied, changed from r111418, cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp
cfe/branches/Apple/williamson/test/CodeGen/_Bool-conversion.c
Modified:
cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp?rev=112510&r1=112509&r2=112510&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp Mon Aug 30 15:20:12 2010
@@ -1027,18 +1027,23 @@
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: {
Copied: cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp.orig (from r111418, cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp.orig?p2=cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp.orig&p1=cfe/branches/Apple/williamson/lib/CodeGen/CGExprScalar.cpp&r1=111418&r2=112510&rev=112510&view=diff
==============================================================================
(empty)
Added: cfe/branches/Apple/williamson/test/CodeGen/_Bool-conversion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/test/CodeGen/_Bool-conversion.c?rev=112510&view=auto
==============================================================================
--- cfe/branches/Apple/williamson/test/CodeGen/_Bool-conversion.c (added)
+++ cfe/branches/Apple/williamson/test/CodeGen/_Bool-conversion.c Mon Aug 30 15:20:12 2010
@@ -0,0 +1,8 @@
+// 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); }
More information about the llvm-branch-commits
mailing list