(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic/
stdatomic-generic.c
       1  /* Test generic atomic routines for proper function calling.  */
       2  /* { dg-do run } */
       3  /* { dg-options "-std=c11 -pedantic-errors" } */
       4  
       5  #include <stdatomic.h>
       6  
       7  extern void abort (void);
       8  extern int memcmp (const void *, const void *, __SIZE_TYPE__);
       9  
      10  typedef struct test {
      11    int array[10];
      12  } test_struct;
      13  
      14  test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
      15  test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
      16  _Atomic test_struct a;
      17  test_struct b;
      18  
      19  int size = sizeof (test_struct);
      20  /* Test for consistency on sizes 1, 2, 4, 8, 16 and 32.  */
      21  int
      22  main ()
      23  {
      24    test_struct c;
      25  
      26    atomic_store_explicit (&a, zero, memory_order_relaxed);
      27    if (memcmp (&a, &zero, size))
      28      abort ();
      29  
      30    c = atomic_exchange_explicit (&a, ones, memory_order_seq_cst);
      31    if (memcmp (&c, &zero, size))
      32      abort ();
      33    if (memcmp (&a, &ones, size))
      34      abort ();
      35  
      36    b = atomic_load_explicit (&a, memory_order_relaxed);
      37    if (memcmp (&b, &ones, size))
      38      abort ();
      39  
      40    if (!atomic_compare_exchange_strong_explicit (&a, &b, zero, memory_order_seq_cst, memory_order_acquire))
      41      abort ();
      42    if (memcmp (&a, &zero, size))
      43      abort ();
      44  
      45    if (atomic_compare_exchange_weak_explicit (&a, &b, ones, memory_order_seq_cst, memory_order_acquire))
      46      abort ();
      47    if (memcmp (&b, &zero, size))
      48      abort ();
      49  
      50    return 0;
      51  }
      52