From 780a2eb227c3f395a390a143f61bba1724913817 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 21 Sep 2010 23:35:30 +0000 Subject: [PATCH] same bug as before, this time with __sync_val_compare_and_swap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114502 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBuiltin.cpp | 10 ++++++---- test/CodeGen/atomic.c | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index e9755f9b0c..d00f1c1d79 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -35,7 +35,7 @@ static void EmitMemoryBarrier(CodeGenFunction &CGF, Value *C[5] = { LoadLoad ? True : False, LoadStore ? True : False, StoreLoad ? True : False, - StoreStore ? True : False, + StoreStore ? True : False, Device ? True : False }; CGF.Builder.CreateCall(CGF.CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5); @@ -788,16 +788,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BI__sync_val_compare_and_swap_4: case Builtin::BI__sync_val_compare_and_swap_8: case Builtin::BI__sync_val_compare_and_swap_16: { + llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); + unsigned AddrSpace = + cast(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 = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, IntrinsicTypes, 2); - Value *Args[3] = { Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)), - PtrType), + Value *Args[3] = { Builder.CreateBitCast(DestPtr, PtrType), EmitCastToInt(CGF, ValueType, CGF.EmitScalarExpr(E->getArg(1))), EmitCastToInt(CGF, ValueType, diff --git a/test/CodeGen/atomic.c b/test/CodeGen/atomic.c index f194ec6afb..6b80e6dda6 100644 --- a/test/CodeGen/atomic.c +++ b/test/CodeGen/atomic.c @@ -134,7 +134,13 @@ void release_return(int *lock) { void addrspace(int __attribute__((address_space(256))) * P) { __sync_bool_compare_and_swap(P, 0, 1); // 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)* %tmp, i32 0, i32 1) + // 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_val_compare_and_swap(P, 0, 1); + // 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) } -- 2.40.0