1 /* PR c/69104.  Test atomic routines for invalid memory model errors.  This
2    only needs to be tested on a single size.  */
3 /* { dg-do compile } */
4 /* { dg-require-effective-target sync_int_long } */
5 
6 #include <stdatomic.h>
7 
8 /* atomic_store_explicit():
9    The order argument shall not be memory_order_acquire,
10    memory_order_consume, nor memory_order_acq_rel.  */
11 
12 void
store(atomic_int * i)13 store (atomic_int *i)
14 {
15   atomic_store_explicit (i, 0, memory_order_consume); /* { dg-warning "invalid memory model" } */
16   atomic_store_explicit (i, 0, memory_order_acquire); /* { dg-warning "invalid memory model" } */
17   atomic_store_explicit (i, 0, memory_order_acq_rel); /* { dg-warning "invalid memory model" } */
18 }
19 
20 /* atomic_load_explicit():
21    The order argument shall not be memory_order_release nor
22    memory_order_acq_rel.  */
23 
24 void
load(atomic_int * i)25 load (atomic_int *i)
26 {
27   atomic_int j = atomic_load_explicit (i, memory_order_release); /* { dg-warning "invalid memory model" } */
28   atomic_int k = atomic_load_explicit (i, memory_order_acq_rel); /* { dg-warning "invalid memory model" } */
29 }
30 
31 /* atomic_compare_exchange():
32    The failure argument shall not be memory_order_release nor
33    memory_order_acq_rel.  The failure argument shall be no stronger than the
34    success argument.  */
35 
36 void
exchange(atomic_int * i)37 exchange (atomic_int *i)
38 {
39   int r;
40 
41   atomic_compare_exchange_strong_explicit (i, &r, 0, memory_order_seq_cst, memory_order_release); /* { dg-warning "invalid failure memory" } */
42   atomic_compare_exchange_strong_explicit (i, &r, 0, memory_order_seq_cst, memory_order_acq_rel); /* { dg-warning "invalid failure memory" } */
43   atomic_compare_exchange_strong_explicit (i, &r, 0, memory_order_relaxed, memory_order_consume); /* { dg-warning "failure memory model cannot be stronger" } */
44 
45   atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_seq_cst, memory_order_release); /* { dg-warning "invalid failure memory" } */
46   atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_seq_cst, memory_order_acq_rel); /* { dg-warning "invalid failure memory" } */
47   atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_relaxed, memory_order_consume); /* { dg-warning "failure memory model cannot be stronger" } */
48 }
49 
50 /* atomic_flag_clear():
51    The order argument shall not be memory_order_acquire nor
52    memory_order_acq_rel.  */
53 
54 void
clear(atomic_int * i)55 clear (atomic_int *i)
56 {
57   atomic_flag_clear_explicit (i, memory_order_acquire); /* { dg-warning "invalid memory model" } */
58   atomic_flag_clear_explicit (i, memory_order_acq_rel); /* { dg-warning "invalid memory model" } */
59 }
60