Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc %s -emit-llvm -o - > %t1 && |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 2 | // RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 && |
| 3 | // RUN: grep @llvm.atomic.load.sub.i32 %t1 | count 3 && |
Argyrios Kyrtzidis | c577a0e | 2008-06-12 12:40:02 +0000 | [diff] [blame] | 4 | // RUN: grep @llvm.atomic.load.min.i32 %t1 && |
| 5 | // RUN: grep @llvm.atomic.load.max.i32 %t1 && |
| 6 | // RUN: grep @llvm.atomic.load.umin.i32 %t1 && |
| 7 | // RUN: grep @llvm.atomic.load.umax.i32 %t1 && |
| 8 | // RUN: grep @llvm.atomic.swap.i32 %t1 && |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 9 | // RUN: grep @llvm.atomic.cmp.swap.i32 %t1 | count 3 && |
| 10 | // RUN: grep @llvm.atomic.load.and.i32 %t1 | count 3 && |
| 11 | // RUN: grep @llvm.atomic.load.or.i32 %t1 | count 3 && |
| 12 | // RUN: grep @llvm.atomic.load.xor.i32 %t1 | count 3 |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 13 | |
| 14 | |
| 15 | int atomic(void) |
| 16 | { |
| 17 | // nonsenical test for sync functions |
| 18 | int old; |
| 19 | int val = 1; |
| 20 | unsigned int uval = 1; |
| 21 | int cmp = 0; |
| 22 | |
| 23 | old = __sync_fetch_and_add(&val, 1); |
| 24 | old = __sync_fetch_and_sub(&val, 2); |
| 25 | old = __sync_fetch_and_min(&val, 3); |
| 26 | old = __sync_fetch_and_max(&val, 4); |
| 27 | old = __sync_fetch_and_umin(&uval, 5u); |
| 28 | old = __sync_fetch_and_umax(&uval, 6u); |
| 29 | old = __sync_lock_test_and_set(&val, 7); |
| 30 | old = __sync_val_compare_and_swap(&val, 4, 1976); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 31 | old = __sync_bool_compare_and_swap(&val, 4, 1976); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 32 | old = __sync_fetch_and_and(&val, 0x9); |
| 33 | old = __sync_fetch_and_or(&val, 0xa); |
| 34 | old = __sync_fetch_and_xor(&val, 0xb); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 35 | |
| 36 | old = __sync_add_and_fetch(&val, 1); |
| 37 | old = __sync_sub_and_fetch(&val, 2); |
| 38 | old = __sync_and_and_fetch(&val, 3); |
| 39 | old = __sync_or_and_fetch(&val, 4); |
| 40 | old = __sync_xor_and_fetch(&val, 5); |
| 41 | |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 42 | return old; |
| 43 | } |