blob: 38d012e6a9a1cd4f7c7d2535e113d33e7906a8d7 [file] [log] [blame]
Douglas Gregor47bfcca2012-04-12 20:42:30 +00001// RUN: %clang_cc1 %s -emit-llvm -O1 -o - -triple=i686-apple-darwin9 | FileCheck %s
David Chisnall3a3c9b22012-04-11 15:29:15 +00002struct A {
3 _Atomic(int) i;
4 A(int j);
5 void v(int j);
6};
7// Storing to atomic values should be atomic
8// CHECK: store atomic i32
9void A::v(int j) { i = j; }
10// Initialising atomic values should not be atomic
11// CHECK-NOT: store atomic
12A::A(int j) : i(j) {}
David Chisnall5d70cfd2012-04-11 17:24:05 +000013
14struct B {
15 int i;
16 B(int x) : i(x) {}
17};
18
19_Atomic(B) b;
20
21// CHECK: define void @_Z11atomic_initR1Ai
22void atomic_init(A& a, int i) {
23 // CHECK-NOT: atomic
Douglas Gregor47bfcca2012-04-12 20:42:30 +000024 // CHECK: tail call void @_ZN1BC1Ei
Richard Smith944b5622012-04-11 18:00:46 +000025 __c11_atomic_init(&b, B(i));
Douglas Gregor47bfcca2012-04-12 20:42:30 +000026 // CHECK-NEXT: ret void
David Chisnall5d70cfd2012-04-11 17:24:05 +000027}
Douglas Gregor47bfcca2012-04-12 20:42:30 +000028
29// CHECK: define void @_Z16atomic_init_boolPU7_Atomicbb
30void atomic_init_bool(_Atomic(bool) *ab, bool b) {
31 // CHECK-NOT: atomic
32 // CHECK: {{zext i1.*to i8}}
33 // CHECK-NEXT: store i8
34 __c11_atomic_init(ab, b);
35 // CHECK-NEXT: ret void
36}
37
38struct AtomicBoolMember {
39 _Atomic(bool) ab;
40 AtomicBoolMember(bool b);
41};
42
43// CHECK: define void @_ZN16AtomicBoolMemberC2Eb
44// CHECK: {{zext i1.*to i8}}
45// CHECK-NEXT: store i8
46// CHECK-NEXT: ret void
47AtomicBoolMember::AtomicBoolMember(bool b) : ab(b) { }
48