]> granicus.if.org Git - clang/commitdiff
Support implicit _Atomic struct load / store
authorJF Bastien <jfbastien@apple.com>
Wed, 18 Jul 2018 18:01:41 +0000 (18:01 +0000)
committerJF Bastien <jfbastien@apple.com>
Wed, 18 Jul 2018 18:01:41 +0000 (18:01 +0000)
Summary:
Using _Atomic to do implicit load / store is just a seq_cst atomic_load / atomic_store. Stores currently assert in Sema::ImpCastExprToType with 'can't implicitly cast lvalue to rvalue with this cast kind', but that's erroneous. The codegen is fine as the test shows.

While investigating I found that Richard had found the problem here: https://reviews.llvm.org/D46112#1113557

<rdar://problem/40347123>

Reviewers: dexonsmith

Subscribers: cfe-commits, efriedma, rsmith, aaron.ballman

Differential Revision: https://reviews.llvm.org/D49458

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337410 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/CodeGen/atomic-ops.c

index 55000e3e350a0c55e2291a13e7062e010d039d36..f81a34c40bd66644053dd24651e50a61039ba1f7 100644 (file)
@@ -481,6 +481,7 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
     case CK_ArrayToPointerDecay:
     case CK_FunctionToPointerDecay:
     case CK_ToVoid:
+    case CK_NonAtomicToAtomic:
       break;
     }
   }
index db97706c5d4921201e3fede69307e560afd5380b..500939f6fd75ac246eb0a9e23edffde54324a232 100644 (file)
@@ -183,6 +183,18 @@ struct S {
   double x;
 };
 
+void implicit_store(_Atomic(struct S) *a, struct S s) {
+  // CHECK-LABEL: @implicit_store(
+  // CHECK: store atomic i64 %{{.*}}, i64* %{{.*}} seq_cst, align 8
+  *a = s;
+}
+
+struct S implicit_load(_Atomic(struct S) *a) {
+  // CHECK-LABEL: @implicit_load(
+  // CHECK: load atomic i64, i64* %{{.*}} seq_cst, align 8
+  return *a;
+}
+
 struct S fd1(struct S *a) {
   // CHECK-LABEL: @fd1
   // CHECK: [[RETVAL:%.*]] = alloca %struct.S, align 4