| 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 |
| 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 |
| 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 |
| 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 model 'memory_order_release'" } */ |
| 42 |
atomic_compare_exchange_strong_explicit (i, &r, 0, memory_order_seq_cst, memory_order_acq_rel); /* { dg-warning "invalid failure memory model 'memory_order_acq_rel'" } */ |
| 43 |
atomic_compare_exchange_strong_explicit (i, &r, 0, memory_order_relaxed, memory_order_consume); /* { dg-warning "failure memory model 'memory_order_consume' cannot be stronger than success memory model 'memory_order_relaxed'" } */ |
| 44 |
|
| 45 |
atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_seq_cst, memory_order_release); /* { dg-warning "invalid failure memory model 'memory_order_release'" } */ |
| 46 |
atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_seq_cst, memory_order_acq_rel); /* { dg-warning "invalid failure memory model 'memory_order_acq_rel'" } */ |
| 47 |
atomic_compare_exchange_weak_explicit (i, &r, 0, memory_order_relaxed, memory_order_consume); /* { dg-warning "failure memory model 'memory_order_consume' cannot be stronger than success memory model 'memory_order_relaxed'" } */ |
| 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 |
| 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 |
} |