Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 > %t1 |
Chandler Carruth | 8d13d22 | 2010-07-18 20:54:12 +0000 | [diff] [blame^] | 2 | // RUN: grep @llvm.memory.barrier %t1 | count 42 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 3 | // RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 |
| 4 | // RUN: grep @llvm.atomic.load.sub.i8 %t1 | count 2 |
| 5 | // RUN: grep @llvm.atomic.load.min.i32 %t1 |
| 6 | // RUN: grep @llvm.atomic.load.max.i32 %t1 |
| 7 | // RUN: grep @llvm.atomic.load.umin.i32 %t1 |
| 8 | // RUN: grep @llvm.atomic.load.umax.i32 %t1 |
| 9 | // RUN: grep @llvm.atomic.swap.i32 %t1 |
Chandler Carruth | 8d13d22 | 2010-07-18 20:54:12 +0000 | [diff] [blame^] | 10 | // RUN: grep @llvm.atomic.cmp.swap.i32 %t1 | count 5 |
Daniel Dunbar | 7eff7c4 | 2010-03-25 17:13:09 +0000 | [diff] [blame] | 11 | // RUN: grep @llvm.atomic.load.and.i32 %t1 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 12 | // RUN: grep @llvm.atomic.load.or.i8 %t1 |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 13 | // RUN: grep @llvm.atomic.load.xor.i8 %t1 |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | int atomic(void) |
| 17 | { |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 18 | // non-sensical test for sync functions |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 19 | int old; |
| 20 | int val = 1; |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 21 | char valc = 1; |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 22 | _Bool valb = 0; |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 23 | unsigned int uval = 1; |
| 24 | int cmp = 0; |
| 25 | |
| 26 | old = __sync_fetch_and_add(&val, 1); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 27 | old = __sync_fetch_and_sub(&valc, 2); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 28 | old = __sync_fetch_and_min(&val, 3); |
| 29 | old = __sync_fetch_and_max(&val, 4); |
| 30 | old = __sync_fetch_and_umin(&uval, 5u); |
| 31 | old = __sync_fetch_and_umax(&uval, 6u); |
| 32 | old = __sync_lock_test_and_set(&val, 7); |
| 33 | old = __sync_val_compare_and_swap(&val, 4, 1976); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 34 | old = __sync_bool_compare_and_swap(&val, 4, 1976); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 35 | old = __sync_fetch_and_and(&val, 0x9); |
| 36 | old = __sync_fetch_and_or(&val, 0xa); |
| 37 | old = __sync_fetch_and_xor(&val, 0xb); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 38 | |
| 39 | old = __sync_add_and_fetch(&val, 1); |
| 40 | old = __sync_sub_and_fetch(&val, 2); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 41 | old = __sync_and_and_fetch(&valc, 3); |
| 42 | old = __sync_or_and_fetch(&valc, 4); |
| 43 | old = __sync_xor_and_fetch(&valc, 5); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 44 | |
Chris Lattner | e7ac0a9 | 2009-05-08 15:36:58 +0000 | [diff] [blame] | 45 | |
| 46 | __sync_val_compare_and_swap((void **)0, (void *)0, (void *)0); |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 47 | if ( __sync_val_compare_and_swap(&valb, 0, 1)) { |
| 48 | old = 42; |
| 49 | } |
Chandler Carruth | 8d13d22 | 2010-07-18 20:54:12 +0000 | [diff] [blame^] | 50 | __sync_bool_compare_and_swap((void **)0, (void *)0, (void *)0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 51 | |
| 52 | __sync_lock_release(&val); |
| 53 | __sync_synchronize (); |
| 54 | |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 55 | return old; |
| 56 | } |
Chandler Carruth | 8d13d22 | 2010-07-18 20:54:12 +0000 | [diff] [blame^] | 57 | |
| 58 | void release_return(int *lock) { |
| 59 | // Ensure this is actually returning void all the way through. |
| 60 | return __sync_lock_release(lock); |
| 61 | } |