CodeGen: _Atomic(_Complex) shouldn't crash
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 14 Feb 2015 01:48:17 +0000 (01:48 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 14 Feb 2015 01:48:17 +0000 (01:48 +0000)
We could be a little kinder if we did a compare-exchange loop instead of
an atomic-load/store pair.

llvm-svn: 229212

clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/test/CodeGen/atomic_ops.c

index ead8531..cf23e6d 100644 (file)
@@ -820,10 +820,14 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
     return EmitObjCIsaExpr(cast<ObjCIsaExpr>(E));
   case Expr::BinaryOperatorClass:
     return EmitBinaryOperatorLValue(cast<BinaryOperator>(E));
-  case Expr::CompoundAssignOperatorClass:
-    if (!E->getType()->isAnyComplexType())
+  case Expr::CompoundAssignOperatorClass: {
+    QualType Ty = E->getType();
+    if (const AtomicType *AT = Ty->getAs<AtomicType>())
+      Ty = AT->getValueType();
+    if (!Ty->isAnyComplexType())
       return EmitCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
     return EmitComplexCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
+  }
   case Expr::CallExprClass:
   case Expr::CXXMemberCallExprClass:
   case Expr::CXXOperatorCallExprClass:
index 1fea5a1..e0ac08b 100644 (file)
@@ -820,6 +820,8 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
   TestAndClearIgnoreReal();
   TestAndClearIgnoreImag();
   QualType LHSTy = E->getLHS()->getType();
+  if (const AtomicType *AT = LHSTy->getAs<AtomicType>())
+    LHSTy = AT->getValueType();
 
   BinOpInfo OpInfo;
 
index 5f2a196..4f9bc41 100644 (file)
@@ -26,3 +26,11 @@ _Bool bar() {
 // CHECK: ret i1 %[[tobool]]
   return b;
 }
+
+extern _Atomic(_Complex int) x;
+
+void baz(int y) {
+// CHECK-LABEL: @baz
+// CHECK: store atomic
+  x += y;
+}