2010-09-22 07:22:41 +08:00
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 | FileCheck %s
|
|
|
|
|
|
|
|
int atomic(void) {
|
2009-05-28 07:45:33 +08:00
|
|
|
// non-sensical test for sync functions
|
2008-05-10 06:40:52 +08:00
|
|
|
int old;
|
|
|
|
int val = 1;
|
2009-05-08 14:58:22 +08:00
|
|
|
char valc = 1;
|
2010-07-18 15:23:17 +08:00
|
|
|
_Bool valb = 0;
|
2008-05-10 06:40:52 +08:00
|
|
|
unsigned int uval = 1;
|
|
|
|
int cmp = 0;
|
2012-03-16 09:48:04 +08:00
|
|
|
int* ptrval;
|
2008-05-10 06:40:52 +08:00
|
|
|
|
|
|
|
old = __sync_fetch_and_add(&val, 1);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw add i32* %val, i32 1 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2009-05-08 14:58:22 +08:00
|
|
|
old = __sync_fetch_and_sub(&valc, 2);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw sub i8* %valc, i8 2 seq_cst, align 1
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_min(&val, 3);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw min i32* %val, i32 3 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_max(&val, 4);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw max i32* %val, i32 4 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_umin(&uval, 5u);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw umin i32* %uval, i32 5 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_umax(&uval, 6u);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw umax i32* %uval, i32 6 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_lock_test_and_set(&val, 7);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw xchg i32* %val, i32 7 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2011-04-09 11:57:26 +08:00
|
|
|
old = __sync_swap(&val, 8);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw xchg i32* %val, i32 8 seq_cst, align 4
|
2011-04-09 11:57:26 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_val_compare_and_swap(&val, 4, 1976);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg i32* %val, i32 4, i32 1976 seq_cst seq_cst, align 4
|
2014-06-13 22:24:59 +08:00
|
|
|
// CHECK: extractvalue { i32, i1 } [[PAIR]], 0
|
|
|
|
|
2009-04-07 08:55:51 +08:00
|
|
|
old = __sync_bool_compare_and_swap(&val, 4, 1976);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg i32* %val, i32 4, i32 1976 seq_cst seq_cst, align 4
|
2014-06-13 22:24:59 +08:00
|
|
|
// CHECK: extractvalue { i32, i1 } [[PAIR]], 1
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_and(&val, 0x9);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw and i32* %val, i32 9 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
old = __sync_fetch_and_or(&val, 0xa);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw or i32* %val, i32 10 seq_cst, align 4
|
2009-04-07 08:55:51 +08:00
|
|
|
|
2010-09-22 07:22:41 +08:00
|
|
|
old = __sync_fetch_and_xor(&val, 0xb);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw xor i32* %val, i32 11 seq_cst, align 4
|
2014-10-03 04:53:50 +08:00
|
|
|
|
|
|
|
old = __sync_fetch_and_nand(&val, 0xc);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw nand i32* %val, i32 12 seq_cst, align 4
|
2014-10-03 04:53:50 +08:00
|
|
|
|
2009-04-07 08:55:51 +08:00
|
|
|
old = __sync_add_and_fetch(&val, 1);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw add i32* %val, i32 1 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2009-04-07 08:55:51 +08:00
|
|
|
old = __sync_sub_and_fetch(&val, 2);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw sub i32* %val, i32 2 seq_cst, align 4
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2009-05-08 14:58:22 +08:00
|
|
|
old = __sync_and_and_fetch(&valc, 3);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw and i8* %valc, i8 3 seq_cst, align 1
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2009-05-08 14:58:22 +08:00
|
|
|
old = __sync_or_and_fetch(&valc, 4);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw or i8* %valc, i8 4 seq_cst, align 1
|
2009-04-07 08:55:51 +08:00
|
|
|
|
2010-09-22 07:22:41 +08:00
|
|
|
old = __sync_xor_and_fetch(&valc, 5);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw xor i8* %valc, i8 5 seq_cst, align 1
|
2014-10-03 04:53:50 +08:00
|
|
|
|
|
|
|
old = __sync_nand_and_fetch(&valc, 6);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw nand i8* %valc, i8 6 seq_cst, align 1
|
2014-10-03 04:53:50 +08:00
|
|
|
|
2009-05-08 23:36:58 +08:00
|
|
|
__sync_val_compare_and_swap((void **)0, (void *)0, (void *)0);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg i32* null, i32 0, i32 0 seq_cst seq_cst, align 4
|
2014-06-13 22:24:59 +08:00
|
|
|
// CHECK: extractvalue { i32, i1 } [[PAIR]], 0
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2010-07-18 15:23:17 +08:00
|
|
|
if ( __sync_val_compare_and_swap(&valb, 0, 1)) {
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: [[PAIR:%[a-z0-9_.]+]] = cmpxchg i8* %valb, i8 0, i8 1 seq_cst seq_cst, align 1
|
2014-06-13 22:24:59 +08:00
|
|
|
// CHECK: [[VAL:%[a-z0-9_.]+]] = extractvalue { i8, i1 } [[PAIR]], 0
|
|
|
|
// CHECK: trunc i8 [[VAL]] to i1
|
2010-07-18 15:23:17 +08:00
|
|
|
old = 42;
|
|
|
|
}
|
2010-09-22 07:22:41 +08:00
|
|
|
|
2010-07-19 04:54:12 +08:00
|
|
|
__sync_bool_compare_and_swap((void **)0, (void *)0, (void *)0);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: cmpxchg i32* null, i32 0, i32 0 seq_cst seq_cst, align 4
|
2009-05-13 12:46:13 +08:00
|
|
|
|
|
|
|
__sync_lock_release(&val);
|
2012-03-16 09:48:04 +08:00
|
|
|
// CHECK: store atomic i32 0, {{.*}} release, align 4
|
|
|
|
|
|
|
|
__sync_lock_release(&ptrval);
|
|
|
|
// CHECK: store atomic i32 0, {{.*}} release, align 4
|
|
|
|
|
2009-05-13 12:46:13 +08:00
|
|
|
__sync_synchronize ();
|
2011-09-07 09:41:24 +08:00
|
|
|
// CHECK: fence seq_cst
|
2009-05-13 12:46:13 +08:00
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
return old;
|
|
|
|
}
|
2010-07-19 04:54:12 +08:00
|
|
|
|
2010-09-22 07:24:52 +08:00
|
|
|
// CHECK: @release_return
|
2010-07-19 04:54:12 +08:00
|
|
|
void release_return(int *lock) {
|
|
|
|
// Ensure this is actually returning void all the way through.
|
|
|
|
return __sync_lock_release(lock);
|
2011-09-14 06:21:56 +08:00
|
|
|
// CHECK: store atomic {{.*}} release, align 4
|
2010-07-19 04:54:12 +08:00
|
|
|
}
|
2010-09-22 07:24:52 +08:00
|
|
|
|
|
|
|
|
2010-09-22 07:40:48 +08:00
|
|
|
// rdar://8461279 - Atomics with address spaces.
|
2010-09-22 07:24:52 +08:00
|
|
|
// CHECK: @addrspace
|
|
|
|
void addrspace(int __attribute__((address_space(256))) * P) {
|
|
|
|
__sync_bool_compare_and_swap(P, 0, 1);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: cmpxchg i32 addrspace(256)*{{.*}}, i32 0, i32 1 seq_cst seq_cst, align 4
|
2011-09-07 09:41:24 +08:00
|
|
|
|
2010-09-22 07:35:30 +08:00
|
|
|
__sync_val_compare_and_swap(P, 0, 1);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: cmpxchg i32 addrspace(256)*{{.*}}, i32 0, i32 1 seq_cst seq_cst, align 4
|
2011-09-07 09:41:24 +08:00
|
|
|
|
2010-09-22 07:40:48 +08:00
|
|
|
__sync_xor_and_fetch(P, 123);
|
2021-02-12 06:33:43 +08:00
|
|
|
// CHECK: atomicrmw xor i32 addrspace(256)*{{.*}}, i32 123 seq_cst, align 4
|
2010-09-22 07:24:52 +08:00
|
|
|
}
|