view gcc/testsuite/gcc.dg/atomic-noinline.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* Test generic __atomic routines for proper function calling.
   memory model.  */
/* { dg-options "-w -fno-inline-atomics" } */
/* { dg-do run } */
/* { dg-additional-sources "atomic-noinline-aux.c" } */

/* Test that -fno-inline-atomics works as expected.  
   atomic-generic-aux provide the expected routines which simply set the
   value of the first parameter to */

#include <stdlib.h>
#include <stdbool.h>

extern void abort (void);

short as,bs,cs,ds;
char ac,bc,cc;

int
main (void)
{

  ac = __atomic_exchange_n (&bc, cc, __ATOMIC_RELAXED);
  if (bc != 1)
    abort ();

  as = __atomic_load_n (&bs, __ATOMIC_SEQ_CST);
  if (bs != 1)
    abort ();

  __atomic_store_n (&ac, bc, __ATOMIC_RELAXED);
  if (ac != 1)
    abort ();

  __atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
  if (as != 1)
    abort ();

  ac = __atomic_fetch_add (&cc, 15, __ATOMIC_SEQ_CST);
  if (cc != 1)
    abort ();

  /* This should be translated to __atomic_fetch_add for the library */
  as = __atomic_add_fetch (&cs, 10, __ATOMIC_RELAXED);
  if (cs != 1)
    abort ();

  /* PR 51040 was caused by arithmetic code not patching up nand_fetch properly
     when used an an external function.  Look for proper return value here.  */
  ac = 0x3C;
  bc = __atomic_nand_fetch (&ac, 0x0f, __ATOMIC_RELAXED);
  if (bc != ac)
    abort ();

  if (!__atomic_is_lock_free (2, &ds))
    abort ();
  if (ds != 1)
    abort ();

  return 0;
}