aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-09-21 23:40:48 +0000
committerChris Lattner <sabre@nondot.org>2010-09-21 23:40:48 +0000
commit4f209445c06a43283c6f72dda7c925538b1578e9 (patch)
tree97df33c6b1ab8c66f82b3ffe49effafab3e24c1e
parent780a2eb227c3f395a390a143f61bba1724913817 (diff)
fix the rest of rdar://8461279 - clang miscompiles address-space qualified atomics
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114503 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGBuiltin.cpp21
-rw-r--r--test/CodeGen/atomic.c8
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index d00f1c1d79..9e7510461b 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -85,15 +85,17 @@ static Value *EmitCallWithBarrier(CodeGenFunction &CGF, Value *Fn,
/// and the expression node.
static RValue EmitBinaryAtomic(CodeGenFunction &CGF,
Intrinsic::ID Id, const CallExpr *E) {
+ llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
+ unsigned AddrSpace =
+ cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
const llvm::Type *ValueType =
llvm::IntegerType::get(CGF.getLLVMContext(),
CGF.getContext().getTypeSize(E->getType()));
- const llvm::Type *PtrType = ValueType->getPointerTo();
+ const llvm::Type *PtrType = ValueType->getPointerTo(AddrSpace);
const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType };
Value *AtomF = CGF.CGM.getIntrinsic(Id, IntrinsicTypes, 2);
- Value *Args[2] = { CGF.Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)),
- PtrType),
+ Value *Args[2] = { CGF.Builder.CreateBitCast(DestPtr, PtrType),
EmitCastToInt(CGF, ValueType,
CGF.EmitScalarExpr(E->getArg(1))) };
return RValue::get(EmitCastFromInt(CGF, E->getType(),
@@ -107,15 +109,18 @@ static RValue EmitBinaryAtomic(CodeGenFunction &CGF,
static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
Intrinsic::ID Id, const CallExpr *E,
Instruction::BinaryOps Op) {
+ llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
+ unsigned AddrSpace =
+ cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
+
const llvm::Type *ValueType =
llvm::IntegerType::get(CGF.getLLVMContext(),
CGF.getContext().getTypeSize(E->getType()));
- const llvm::Type *PtrType = ValueType->getPointerTo();
+ const llvm::Type *PtrType = ValueType->getPointerTo(AddrSpace);
const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType };
Value *AtomF = CGF.CGM.getIntrinsic(Id, IntrinsicTypes, 2);
- Value *Args[2] = { CGF.Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)),
- PtrType),
+ Value *Args[2] = { CGF.Builder.CreateBitCast(DestPtr, PtrType),
EmitCastToInt(CGF, ValueType,
CGF.EmitScalarExpr(E->getArg(1))) };
Value *Result = EmitCallWithBarrier(CGF, AtomF, Args, Args + 2);
@@ -790,7 +795,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BI__sync_val_compare_and_swap_16: {
llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
unsigned AddrSpace =
- cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();;
+ cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
const llvm::Type *ValueType =
llvm::IntegerType::get(CGF.getLLVMContext(),
CGF.getContext().getTypeSize(E->getType()));
@@ -816,7 +821,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BI__sync_bool_compare_and_swap_16: {
llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
unsigned AddrSpace =
- cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();;
+ cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
const llvm::Type *ValueType =
llvm::IntegerType::get(CGF.getLLVMContext(),
CGF.getContext().getTypeSize(E->getArg(1)->getType()));
diff --git a/test/CodeGen/atomic.c b/test/CodeGen/atomic.c
index 6b80e6dda6..e3bc2185b7 100644
--- a/test/CodeGen/atomic.c
+++ b/test/CodeGen/atomic.c
@@ -130,6 +130,7 @@ void release_return(int *lock) {
}
+// rdar://8461279 - Atomics with address spaces.
// CHECK: @addrspace
void addrspace(int __attribute__((address_space(256))) * P) {
__sync_bool_compare_and_swap(P, 0, 1);
@@ -142,5 +143,12 @@ void addrspace(int __attribute__((address_space(256))) * P) {
// CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true)
// CHECK: call i32 @llvm.atomic.cmp.swap.i32.p256i32(i32 addrspace(256)*{{.*}}, i32 0, i32 1)
// CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true)
+
+
+ __sync_xor_and_fetch(P, 123);
+ // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true)
+ // CHECK: call i32 @llvm.atomic.load.xor.i32.p256i32(i32 addrspace(256)* {{.*}}, i32 123)
+ // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 true, i1 true, i1 true)
+
}