[cfe-commits] r154507 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/atomicinit.cpp

David Chisnall csdavec at swan.ac.uk
Wed Apr 11 10:24:05 PDT 2012


Author: theraven
Date: Wed Apr 11 12:24:05 2012
New Revision: 154507

URL: http://llvm.org/viewvc/llvm-project?rev=154507&view=rev
Log:
Make __atomic_init() (soon to be __c11_atomic_init()) work with non-scalar types.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/atomicinit.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=154507&r1=154506&r2=154507&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Apr 11 12:24:05 2012
@@ -2786,10 +2786,21 @@
 
   if (E->getOp() == AtomicExpr::Init) {
     assert(!Dest && "Init does not return a value");
-    Val1 = EmitScalarExpr(E->getVal1());
-    llvm::StoreInst *Store = Builder.CreateStore(Val1, Ptr);
-    Store->setAlignment(Size);
-    Store->setVolatile(E->isVolatile());
+    if (!hasAggregateLLVMType(E->getVal1()->getType())) {
+      llvm::StoreInst *Store =
+        Builder.CreateStore(EmitScalarExpr(E->getVal1()), Ptr);
+      Store->setAlignment(Size);
+      Store->setVolatile(E->isVolatile());
+    } else if (E->getType()->isAnyComplexType()) {
+      EmitComplexExprIntoAddr(E->getVal1(), Ptr, E->isVolatile());
+    } else {
+      AggValueSlot Slot = AggValueSlot::forAddr(Ptr, alignChars,
+                                        AtomicTy.getQualifiers(),
+                                        AggValueSlot::IsNotDestructed,
+                                        AggValueSlot::DoesNotNeedGCBarriers,
+                                        AggValueSlot::IsNotAliased);
+      EmitAggExpr(E->getVal1(), Slot);
+    }
     return RValue::get(0);
   }
 

Modified: cfe/trunk/test/CodeGenCXX/atomicinit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomicinit.cpp?rev=154507&r1=154506&r2=154507&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/atomicinit.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/atomicinit.cpp Wed Apr 11 12:24:05 2012
@@ -10,3 +10,16 @@
 // Initialising atomic values should not be atomic
 // CHECK-NOT: store atomic 
 A::A(int j) : i(j) {}
+
+struct B {
+  int i;
+  B(int x) : i(x) {}
+};
+
+_Atomic(B) b;
+
+// CHECK: define void @_Z11atomic_initR1Ai
+void atomic_init(A& a, int i) {
+  // CHECK-NOT: atomic
+  __atomic_init(&b, B(i));
+}





More information about the cfe-commits mailing list