fix a problem reported by Eli, caused by not keeping bool as i1
when in a register.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46552 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 41eb275..cb0f42a 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -115,8 +115,17 @@
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);