Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only |
| 2 | |
| 3 | // Basic parsing/Sema tests for __atomic_* |
| 4 | |
| 5 | // FIXME: Need to implement __atomic_is_lock_free |
| 6 | |
| 7 | typedef enum memory_order { |
| 8 | memory_order_relaxed, memory_order_consume, memory_order_acquire, |
| 9 | memory_order_release, memory_order_acq_rel, memory_order_seq_cst |
| 10 | } memory_order; |
| 11 | |
| 12 | void f(_Atomic(int) *i, _Atomic(int*) *p, _Atomic(float) *d) { |
| 13 | __atomic_load(0); // expected-error {{too few arguments to function}} |
| 14 | __atomic_load(0,0,0); // expected-error {{too many arguments to function}} |
| 15 | __atomic_store(0,0,0); // expected-error {{first argument to atomic operation}} |
| 16 | __atomic_store((int*)0,0,0); // expected-error {{first argument to atomic operation}} |
| 17 | |
| 18 | __atomic_load(i, memory_order_seq_cst); |
| 19 | __atomic_load(p, memory_order_seq_cst); |
| 20 | __atomic_load(d, memory_order_seq_cst); |
| 21 | |
| 22 | __atomic_store(i, 1, memory_order_seq_cst); |
| 23 | __atomic_store(p, 1, memory_order_seq_cst); // expected-warning {{incompatible integer to pointer conversion}} |
| 24 | (int)__atomic_store(d, 1, memory_order_seq_cst); // expected-error {{operand of type 'void'}} |
| 25 | |
| 26 | __atomic_fetch_add(i, 1, memory_order_seq_cst); |
| 27 | __atomic_fetch_add(p, 1, memory_order_seq_cst); |
| 28 | __atomic_fetch_add(d, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer or pointer}} |
| 29 | |
| 30 | __atomic_fetch_and(i, 1, memory_order_seq_cst); |
| 31 | __atomic_fetch_and(p, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer}} |
| 32 | __atomic_fetch_and(d, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer}} |
| 33 | |
| 34 | __atomic_compare_exchange_strong(i, 0, 1, memory_order_seq_cst, memory_order_seq_cst); |
| 35 | __atomic_compare_exchange_strong(p, 0, (int*)1, memory_order_seq_cst, memory_order_seq_cst); |
| 36 | __atomic_compare_exchange_strong(d, (int*)0, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}} |
| 37 | } |