summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-30 07:01:17 +0000
committerChris Lattner <sabre@nondot.org>2008-01-30 07:01:17 +0000
commit05ba4cbe178057a2a0588ddba2eb25d38902c34d (patch)
treed7135909fe4b508cadb953537a731a9fdc8382b8 /clang
parente850fa2452d902f96e9a1866a612ed3a5c5dd9b7 (diff)
downloadbcm5719-llvm-05ba4cbe178057a2a0588ddba2eb25d38902c34d.tar.gz
bcm5719-llvm-05ba4cbe178057a2a0588ddba2eb25d38902c34d.zip
fix a problem reported by Eli, caused by not keeping bool as i1
when in a register. llvm-svn: 46552
Diffstat (limited to 'clang')
-rw-r--r--clang/CodeGen/CGExpr.cpp13
-rw-r--r--clang/test/CodeGen/exprs.c3
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/CodeGen/CGExpr.cpp b/clang/CodeGen/CGExpr.cpp
index 41eb2756a4d..cb0f42a645e 100644
--- a/clang/CodeGen/CGExpr.cpp
+++ b/clang/CodeGen/CGExpr.cpp
@@ -115,8 +115,17 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
cast<llvm::PointerType>(Ptr->getType())->getElementType();
// Simple scalar l-value.
- if (EltTy->isFirstClassType())
- return RValue::get(Builder.CreateLoad(Ptr, "tmp"));
+ if (EltTy->isFirstClassType()) {
+ llvm::Value *V = Builder.CreateLoad(Ptr, "tmp");
+
+ // Bool can have different representation in memory than in registers.
+ if (ExprType->isBooleanType()) {
+ if (V->getType() != llvm::Type::Int1Ty)
+ V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool");
+ }
+
+ return RValue::get(V);
+ }
assert(ExprType->isFunctionType() && "Unknown scalar value");
return RValue::get(Ptr);
diff --git a/clang/test/CodeGen/exprs.c b/clang/test/CodeGen/exprs.c
index 502cb83c131..91153691733 100644
--- a/clang/test/CodeGen/exprs.c
+++ b/clang/test/CodeGen/exprs.c
@@ -14,3 +14,6 @@ void *test(int *i) {
a + i;
}
+_Bool test2b;
+int test2() {if (test2b);}
+
OpenPOWER on IntegriCloud