aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-10-27 17:13:49 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-10-27 17:13:49 +0000
commit11893327d056a7ebd820da8f00a3286e7430a91c (patch)
tree682cbed34301c13baa54b76b22635d44645ac20e /lib/CodeGen/CGExpr.cpp
parent354e712c81fbb07c0ce5f06180788b25fffa1b56 (diff)
Revert r117403 as it caused PR8480.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117456 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 85cd0c0c30..7bc8159a3d 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -590,7 +590,13 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
if (TBAAInfo)
CGM.DecorateInstruction(Load, TBAAInfo);
- return EmitFromMemory(Load, Ty);
+ // Bool can have different representation in memory than in registers.
+ llvm::Value *V = Load;
+ if (Ty->isBooleanType())
+ if (V->getType() != llvm::Type::getInt1Ty(VMContext))
+ V = Builder.CreateTrunc(V, llvm::Type::getInt1Ty(VMContext), "tobool");
+
+ return V;
}
static bool isBooleanUnderlyingType(QualType Ty) {
@@ -599,31 +605,17 @@ static bool isBooleanUnderlyingType(QualType Ty) {
return false;
}
-llvm::Value *CodeGenFunction::EmitToMemory(llvm::Value *Value, QualType Ty) {
- // Bool has a different representation in memory than in registers.
- if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) {
- assert(Value->getType()->isIntegerTy(1) && "value rep of bool not i1");
- return Builder.CreateZExt(Value, Builder.getInt8Ty(), "frombool");
- }
-
- return Value;
-}
-
-llvm::Value *CodeGenFunction::EmitFromMemory(llvm::Value *Value, QualType Ty) {
- // Bool has a different representation in memory than in registers.
- if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) {
- assert(Value->getType()->isIntegerTy(8) && "memory rep of bool not i8");
- return Builder.CreateTrunc(Value, Builder.getInt1Ty(), "tobool");
- }
-
- return Value;
-}
-
void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
bool Volatile, unsigned Alignment,
QualType Ty,
llvm::MDNode *TBAAInfo) {
- Value = EmitToMemory(Value, Ty);
+
+ if (Ty->isBooleanType() || isBooleanUnderlyingType(Ty)) {
+ // Bool can have different representation in memory than in registers.
+ const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType());
+ Value = Builder.CreateIntCast(Value, DstPtr->getElementType(), false);
+ }
+
llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
if (Alignment)
Store->setAlignment(Alignment);