2011-10-11 10:20:01 +08:00
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
|
|
|
|
|
2012-04-11 06:49:28 +08:00
|
|
|
// Also test serialization of atomic operations here, to avoid duplicating the
|
|
|
|
// test.
|
|
|
|
// RUN: %clang_cc1 %s -emit-pch -o %t -triple=i686-apple-darwin9
|
|
|
|
// RUN: %clang_cc1 %s -include-pch %t -triple=i686-apple-darwin9 -emit-llvm -o - | FileCheck %s
|
|
|
|
#ifndef ALREADY_INCLUDED
|
|
|
|
#define ALREADY_INCLUDED
|
|
|
|
|
2012-04-12 01:55:32 +08:00
|
|
|
// Basic IRGen tests for __c11_atomic_*
|
2011-10-11 10:20:01 +08:00
|
|
|
|
2012-04-12 01:55:32 +08:00
|
|
|
// FIXME: Need to implement __c11_atomic_is_lock_free
|
2011-10-11 10:20:01 +08:00
|
|
|
|
|
|
|
typedef enum memory_order {
|
|
|
|
memory_order_relaxed, memory_order_consume, memory_order_acquire,
|
|
|
|
memory_order_release, memory_order_acq_rel, memory_order_seq_cst
|
|
|
|
} memory_order;
|
|
|
|
|
|
|
|
int fi1(_Atomic(int) *i) {
|
|
|
|
// CHECK: @fi1
|
|
|
|
// CHECK: load atomic i32* {{.*}} seq_cst
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_load(i, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void fi2(_Atomic(int) *i) {
|
|
|
|
// CHECK: @fi2
|
|
|
|
// CHECK: store atomic i32 {{.*}} seq_cst
|
2012-04-12 01:55:32 +08:00
|
|
|
__c11_atomic_store(i, 1, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void fi3(_Atomic(int) *i) {
|
|
|
|
// CHECK: @fi3
|
|
|
|
// CHECK: atomicrmw and
|
2012-04-12 01:55:32 +08:00
|
|
|
__c11_atomic_fetch_and(i, 1, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void fi4(_Atomic(int) *i) {
|
|
|
|
// CHECK: @fi4
|
|
|
|
// CHECK: cmpxchg i32*
|
|
|
|
int cmp = 0;
|
2012-04-12 01:55:32 +08:00
|
|
|
__c11_atomic_compare_exchange_strong(i, &cmp, 1, memory_order_acquire, memory_order_acquire);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float ff1(_Atomic(float) *d) {
|
|
|
|
// CHECK: @ff1
|
|
|
|
// CHECK: load atomic i32* {{.*}} monotonic
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_load(d, memory_order_relaxed);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff2(_Atomic(float) *d) {
|
|
|
|
// CHECK: @ff2
|
|
|
|
// CHECK: store atomic i32 {{.*}} release
|
2012-04-12 01:55:32 +08:00
|
|
|
__c11_atomic_store(d, 1, memory_order_release);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float ff3(_Atomic(float) *d) {
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_exchange(d, 2, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int* fp1(_Atomic(int*) *p) {
|
|
|
|
// CHECK: @fp1
|
|
|
|
// CHECK: load atomic i32* {{.*}} seq_cst
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_load(p, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int* fp2(_Atomic(int*) *p) {
|
|
|
|
// CHECK: @fp2
|
|
|
|
// CHECK: store i32 4
|
|
|
|
// CHECK: atomicrmw add {{.*}} monotonic
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_fetch_add(p, 1, memory_order_relaxed);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 04:59:01 +08:00
|
|
|
_Complex float fc(_Atomic(_Complex float) *c) {
|
2011-10-11 10:20:01 +08:00
|
|
|
// CHECK: @fc
|
|
|
|
// CHECK: atomicrmw xchg i64*
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_exchange(c, 2, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct X { int x; } X;
|
|
|
|
X fs(_Atomic(X) *c) {
|
|
|
|
// CHECK: @fs
|
|
|
|
// CHECK: atomicrmw xchg i32*
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_exchange(c, (X){2}, memory_order_seq_cst);
|
2011-10-11 10:20:01 +08:00
|
|
|
}
|
2011-10-18 05:44:23 +08:00
|
|
|
|
|
|
|
int lock_free() {
|
|
|
|
// CHECK: @lock_free
|
|
|
|
// CHECK: ret i32 1
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_is_lock_free(sizeof(_Atomic(int)));
|
2011-10-18 05:48:31 +08:00
|
|
|
}
|
2012-03-30 02:01:11 +08:00
|
|
|
|
|
|
|
// Tests for atomic operations on big values. These should call the functions
|
|
|
|
// defined here:
|
|
|
|
// http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary#The_Library_interface
|
|
|
|
|
|
|
|
struct foo {
|
|
|
|
int big[128];
|
|
|
|
};
|
|
|
|
|
|
|
|
_Atomic(struct foo) bigAtomic;
|
|
|
|
|
|
|
|
void structAtomicStore() {
|
|
|
|
// CHECK: @structAtomicStore
|
|
|
|
struct foo f = {0};
|
2012-04-12 01:55:32 +08:00
|
|
|
__c11_atomic_store(&bigAtomic, f, 5);
|
2012-03-30 02:41:08 +08:00
|
|
|
// CHECK: call void @__atomic_store(i32 512, i8* bitcast (%struct.foo* @bigAtomic to i8*),
|
2012-03-30 02:01:11 +08:00
|
|
|
}
|
|
|
|
void structAtomicLoad() {
|
|
|
|
// CHECK: @structAtomicLoad
|
2012-04-12 01:55:32 +08:00
|
|
|
struct foo f = __c11_atomic_load(&bigAtomic, 5);
|
2012-03-30 02:41:08 +08:00
|
|
|
// CHECK: call void @__atomic_load(i32 512, i8* bitcast (%struct.foo* @bigAtomic to i8*),
|
2012-03-30 02:01:11 +08:00
|
|
|
}
|
|
|
|
struct foo structAtomicExchange() {
|
|
|
|
// CHECK: @structAtomicExchange
|
|
|
|
struct foo f = {0};
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_exchange(&bigAtomic, f, 5);
|
2012-03-30 02:41:08 +08:00
|
|
|
// CHECK: call void @__atomic_exchange(i32 512, i8* bitcast (%struct.foo* @bigAtomic to i8*),
|
2012-03-30 02:01:11 +08:00
|
|
|
}
|
|
|
|
int structAtomicCmpExchange() {
|
|
|
|
// CHECK: @structAtomicCmpExchange
|
|
|
|
struct foo f = {0};
|
|
|
|
struct foo g = {0};
|
|
|
|
g.big[12] = 12;
|
2012-04-12 01:55:32 +08:00
|
|
|
return __c11_atomic_compare_exchange_strong(&bigAtomic, &f, g, 5, 5);
|
2012-03-30 02:41:08 +08:00
|
|
|
// CHECK: call zeroext i1 @__atomic_compare_exchange(i32 512, i8* bitcast (%struct.foo* @bigAtomic to i8*),
|
2012-03-30 02:01:11 +08:00
|
|
|
}
|
2012-04-11 06:49:28 +08:00
|
|
|
|
|
|
|
#endif
|