(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic-noinline.c
       1  /* Test generic __atomic routines for proper function calling.
       2     memory model.  */
       3  /* { dg-options "-w -fno-inline-atomics" } */
       4  /* { dg-do run } */
       5  /* { dg-additional-sources "atomic-noinline-aux.c" } */
       6  
       7  /* Test that -fno-inline-atomics works as expected.  
       8     atomic-generic-aux provide the expected routines which simply set the
       9     value of the first parameter to */
      10  
      11  #include <stdlib.h>
      12  #include <stdbool.h>
      13  
      14  extern void abort (void);
      15  
      16  short as,bs,cs,ds;
      17  char ac,bc,cc;
      18  
      19  int
      20  main (void)
      21  {
      22  
      23    ac = __atomic_exchange_n (&bc, cc, __ATOMIC_RELAXED);
      24    if (bc != 1)
      25      abort ();
      26  
      27    as = __atomic_load_n (&bs, __ATOMIC_SEQ_CST);
      28    if (bs != 1)
      29      abort ();
      30  
      31    __atomic_store_n (&ac, bc, __ATOMIC_RELAXED);
      32    if (ac != 1)
      33      abort ();
      34  
      35    __atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
      36    if (as != 1)
      37      abort ();
      38  
      39    ac = __atomic_fetch_add (&cc, 15, __ATOMIC_SEQ_CST);
      40    if (cc != 1)
      41      abort ();
      42  
      43    /* This should be translated to __atomic_fetch_add for the library */
      44    as = __atomic_add_fetch (&cs, 10, __ATOMIC_RELAXED);
      45    if (cs != 1)
      46      abort ();
      47  
      48    /* PR 51040 was caused by arithmetic code not patching up nand_fetch properly
      49       when used an an external function.  Look for proper return value here.  */
      50    ac = 0x3C;
      51    bc = __atomic_nand_fetch (&ac, 0x0f, __ATOMIC_RELAXED);
      52    if (bc != ac)
      53      abort ();
      54  
      55    if (!__atomic_is_lock_free (2, &ds))
      56      abort ();
      57    if (ds != 1)
      58      abort ();
      59  
      60    return 0;
      61  }