1 // RUN: clang-cc %s -emit-llvm -o - -triple=i686-apple-darwin9 > %t1 && 2 // RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 && 3 // RUN: grep @llvm.atomic.load.sub.i8 %t1 | count 2 && 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 && 9 // RUN: grep @llvm.atomic.cmp.swap.i32 %t1 | count 4 && 10 // RUN: grep @llvm.atomic.load.and.i32 %t1 | count 2 && 11 // RUN: grep @llvm.atomic.load.or.i8 %t1 && 12 // RUN: grep @llvm.atomic.load.xor.i8 %t1 13 14 15 int atomic(void) 16 { 17 // non-sensical test for sync functions 18 int old; 19 int val = 1; 20 char valc = 1; 21 unsigned int uval = 1; 22 int cmp = 0; 23 24 old = __sync_fetch_and_add(&val, 1); 25 old = __sync_fetch_and_sub(&valc, 2); 26 old = __sync_fetch_and_min(&val, 3); 27 old = __sync_fetch_and_max(&val, 4); 28 old = __sync_fetch_and_umin(&uval, 5u); 29 old = __sync_fetch_and_umax(&uval, 6u); 30 old = __sync_lock_test_and_set(&val, 7); 31 old = __sync_val_compare_and_swap(&val, 4, 1976); 32 old = __sync_bool_compare_and_swap(&val, 4, 1976); 33 old = __sync_fetch_and_and(&val, 0x9); 34 old = __sync_fetch_and_or(&val, 0xa); 35 old = __sync_fetch_and_xor(&val, 0xb); 36 old = __sync_fetch_and_nand(&val, 0xb); 37 38 old = __sync_add_and_fetch(&val, 1); 39 old = __sync_sub_and_fetch(&val, 2); 40 old = __sync_and_and_fetch(&valc, 3); 41 old = __sync_or_and_fetch(&valc, 4); 42 old = __sync_xor_and_fetch(&valc, 5); 43 old = __sync_nand_and_fetch(&valc, 5); 44 45 46 __sync_val_compare_and_swap((void **)0, (void *)0, (void *)0); 47 48 49 __sync_lock_release(&val); 50 __sync_synchronize (); 51 52 return old; 53 } 54