1/* Test generic __atomic routines for proper function calling. 2 memory model. */ 3/* { dg-options "-w" } */ 4/* { dg-do run } */ 5/* { dg-additional-sources "atomic-generic-aux.c" } */ 6 7/* Test that the generioc atomic builtins execute as expected.. 8 sync-mem-generic-aux.c supplies a functional external entry point for 9 the 4 generic functions. */ 10 11#include <stdlib.h> 12#include <stdbool.h> 13 14extern void abort(); 15 16typedef struct test { 17 int array[10]; 18} test_struct; 19 20test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 21test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; 22test_struct a,b; 23 24int size = sizeof (test_struct); 25/* Test for consistency on sizes 1, 2, 4, 8, 16 and 32. */ 26int 27main () 28{ 29 test_struct c; 30 31 __atomic_store (&a, &zero, __ATOMIC_RELAXED); 32 if (memcmp (&a, &zero, size)) 33 abort (); 34 35 __atomic_exchange (&a, &ones, &c, __ATOMIC_SEQ_CST); 36 if (memcmp (&c, &zero, size)) 37 abort (); 38 if (memcmp (&a, &ones, size)) 39 abort (); 40 41 __atomic_load (&a, &b, __ATOMIC_RELAXED); 42 if (memcmp (&b, &ones, size)) 43 abort (); 44 45 if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE)) 46 abort(); 47 if (memcmp (&a, &zero, size)) 48 abort (); 49 50 if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE)) 51 abort(); 52 if (memcmp (&b, &zero, size)) 53 abort (); 54 55 return 0; 56} 57 58