diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c b/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c new file mode 100644 index 0000000000..5647ee6633 --- /dev/null +++ b/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c @@ -0,0 +1,81 @@ +/* Test atomic_compare_exchange routines for existence and proper + execution on 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v = ATOMIC_VAR_INIT (0); +short expected = 0; +short max = ~0; +short desired = ~0; +short zero = 0; + +int +main () +{ + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, max, memory_order_relaxed, memory_order_relaxed)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_acquire, memory_order_relaxed)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_release, memory_order_acquire)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak_explicit (&v, &expected, desired, memory_order_acq_rel, memory_order_acquire)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, desired, memory_order_seq_cst, memory_order_seq_cst)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + v = 0; + + if (!atomic_compare_exchange_strong (&v, &expected, max)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + return 0; +} |