blob: d1b3cbb0d4b391b6a8185b096592188484d647c1 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc %s -emit-llvm -o - > %t1 &&
Daniel Dunbar0002d232009-04-07 00:55:51 +00002// RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 &&
3// RUN: grep @llvm.atomic.load.sub.i32 %t1 | count 3 &&
Argyrios Kyrtzidisc577a0e2008-06-12 12:40:02 +00004// 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 Dunbar0002d232009-04-07 00:55:51 +00009// 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 Wang1ffe2812008-05-09 22:40:52 +000013
14
15int 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 Dunbar0002d232009-04-07 00:55:51 +000031 old = __sync_bool_compare_and_swap(&val, 4, 1976);
Mon P Wang1ffe2812008-05-09 22:40:52 +000032 old = __sync_fetch_and_and(&val, 0x9);
33 old = __sync_fetch_and_or(&val, 0xa);
34 old = __sync_fetch_and_xor(&val, 0xb);
Daniel Dunbar0002d232009-04-07 00:55:51 +000035
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 Wang1ffe2812008-05-09 22:40:52 +000042 return old;
43}