aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-19 19:36:19 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-19 19:36:19 +0000
commit3bb423bb7f809c9182be3ba79adfbb38854afa64 (patch)
treeee19b5fa509b9d3e45a1556b049b0cef0eb32eef /lib/CodeGen/CGExpr.cpp
parenta3a7b8eea87c90a5a257f685749222b212ddaf36 (diff)
Only do the bitcast in EmitStoreOfScalar if the type is a boolean.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72125 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 24d885cec5..f7c3fd0976 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -200,8 +200,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
QualType Ty) {
llvm::Value *V = Builder.CreateLoad(Addr, Volatile, "tmp");
- // Bool can have different representation in memory than in
- // registers.
+ // Bool can have different representation in memory than in registers.
if (Ty->isBooleanType())
if (V->getType() != llvm::Type::Int1Ty)
V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool");
@@ -211,20 +210,18 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
bool Volatile, QualType Ty) {
- // Handle stores of types which have different representations in memory and
- // as LLVM values.
-
- // FIXME: We shouldn't be this loose, we should only do this conversion when
- // we have a type we know has a different memory representation (e.g., bool).
-
- const llvm::Type *SrcTy = Value->getType();
- const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType());
- if (DstPtr->getElementType() != SrcTy) {
- const llvm::Type *MemTy =
- llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace());
- Addr = Builder.CreateBitCast(Addr, MemTy, "storetmp");
+
+ if (Ty->isBooleanType()) {
+ // Bool can have different representation in memory than in registers.
+ const llvm::Type *SrcTy = Value->getType();
+ const llvm::PointerType *DstPtr = cast<llvm::PointerType>(Addr->getType());
+ if (DstPtr->getElementType() != SrcTy) {
+ const llvm::Type *MemTy =
+ llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace());
+ Addr = Builder.CreateBitCast(Addr, MemTy, "storetmp");
+ }
}
-
+
Builder.CreateStore(Value, Addr, Volatile);
}