From ff993202abf6f5dc41c584c7103f5d39f248b3dd Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 16 Mar 2012 01:48:04 +0000 Subject: [PATCH] Don't try to create "store atomic" instructions of non-integer types; they aren't supported at the moment. PR12040. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152891 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBuiltin.cpp | 9 +++++---- test/CodeGen/atomic.c | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 2a3aa1f2a5..eb849f6e99 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -942,12 +942,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BI__sync_lock_release_8: case Builtin::BI__sync_lock_release_16: { Value *Ptr = EmitScalarExpr(E->getArg(0)); - llvm::Type *ElLLVMTy = - cast(Ptr->getType())->getElementType(); - llvm::StoreInst *Store = - Builder.CreateStore(llvm::Constant::getNullValue(ElLLVMTy), Ptr); QualType ElTy = E->getArg(0)->getType()->getPointeeType(); CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); + llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), + StoreSize.getQuantity() * 8); + Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); + llvm::StoreInst *Store = + Builder.CreateStore(llvm::Constant::getNullValue(ITy), Ptr); Store->setAlignment(StoreSize.getQuantity()); Store->setAtomic(llvm::Release); return RValue::get(0); diff --git a/test/CodeGen/atomic.c b/test/CodeGen/atomic.c index c8f4fd09bb..ac3848f02f 100644 --- a/test/CodeGen/atomic.c +++ b/test/CodeGen/atomic.c @@ -8,6 +8,7 @@ int atomic(void) { _Bool valb = 0; unsigned int uval = 1; int cmp = 0; + int* ptrval; old = __sync_fetch_and_add(&val, 1); // CHECK: atomicrmw add i32* %val, i32 1 seq_cst @@ -75,8 +76,11 @@ int atomic(void) { // CHECK: cmpxchg i32* null, i32 0, i32 0 seq_cst __sync_lock_release(&val); - // CHECK: store atomic {{.*}} release, align 4 - + // CHECK: store atomic i32 0, {{.*}} release, align 4 + + __sync_lock_release(&ptrval); + // CHECK: store atomic i32 0, {{.*}} release, align 4 + __sync_synchronize (); // CHECK: fence seq_cst