diff options
| author | John McCall <rjmccall@apple.com> | 2010-10-26 22:09:15 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-10-26 22:09:15 +0000 |
| commit | 789a1597250e57d7f35f253467165913c68979ad (patch) | |
| tree | df1726f799b6e581d8f4024eaedd8ee76ef5613e /lib/CodeGen/CGExpr.cpp | |
| parent | 9c13f5bc0e0ecdd9f00872fdc0b0ac48e01fec38 (diff) | |
| download | clang-789a1597250e57d7f35f253467165913c68979ad.tar.gz clang-789a1597250e57d7f35f253467165913c68979ad.tar.bz2 clang-789a1597250e57d7f35f253467165913c68979ad.tar.xz | |
Extract procedures to do scalar-to-memory and memory-to-scalar conversions
in IR gen, and use those to fix a correctness issue with bool atomic
intrinsics. rdar://problem/8461234
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117403 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 7bc8159a3d..85cd0c0c30 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -590,13 +590,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, if (TBAAInfo) CGM.DecorateInstruction(Load, TBAAInfo); - // 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; + return EmitFromMemory(Load, Ty); } static bool isBooleanUnderlyingType(QualType Ty) { @@ -605,17 +599,31 @@ static bool isBooleanUnderlyingType(QualType Ty) { return false; } -void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, - bool Volatile, unsigned Alignment, - QualType Ty, - llvm::MDNode *TBAAInfo) { +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)) { - // 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); + 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); llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile); if (Alignment) Store->setAlignment(Alignment); |
