]> granicus.if.org Git - clang/commitdiff
Don't try to create "store atomic" instructions of non-integer types; they aren't...
authorEli Friedman <eli.friedman@gmail.com>
Fri, 16 Mar 2012 01:48:04 +0000 (01:48 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 16 Mar 2012 01:48:04 +0000 (01:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152891 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/atomic.c

index 2a3aa1f2a57facb60a7be83ab0bcfc159fb6b31d..eb849f6e99c4aa7c7d05f4c31e138cc9d3d6c0d2 100644 (file)
@@ -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<llvm::PointerType>(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);
index c8f4fd09bbc514ed809122d2bd7599d083994893..ac3848f02f9e683fe3e5e1be8f819a1c89fbd00c 100644 (file)
@@ -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