| 1 |
/* Test the atomic_init generic function. Verify that __atomic_store_N |
| 2 |
is called with the last argument of memory_order_relaxed (i.e., 0) |
| 3 |
for each invocation of the atomic_init() macro in the test and that |
| 4 |
there are no calls to __atomic_store_N with a non-zero last argument. */ |
| 5 |
/* { dg-do compile } */ |
| 6 |
/* { dg-options "-fdump-tree-gimple -std=c11 -pedantic-errors" } */ |
| 7 |
/* { dg-final { scan-tree-dump-times "__atomic_store_. \\(\[^\n\r]*, 0\\)" 54 "gimple" } } */ |
| 8 |
/* { dg-final { scan-tree-dump-not "__atomic_store_. \\(\[^\n\r]*, \[1-5\]\\)" "gimple" } } */ |
| 9 |
|
| 10 |
#include <stdatomic.h> |
| 11 |
|
| 12 |
struct Atomic { |
| 13 |
/* Volatile to prevent re-initialization from being optimized away. */ |
| 14 |
volatile atomic_bool b; |
| 15 |
volatile atomic_char c; |
| 16 |
volatile atomic_schar sc; |
| 17 |
volatile atomic_uchar uc; |
| 18 |
volatile atomic_short ss; |
| 19 |
volatile atomic_ushort us; |
| 20 |
volatile atomic_int si; |
| 21 |
volatile atomic_uint ui; |
| 22 |
volatile atomic_long sl; |
| 23 |
volatile atomic_ulong ul; |
| 24 |
volatile atomic_llong sll; |
| 25 |
volatile atomic_ullong ull; |
| 26 |
volatile atomic_size_t sz; |
| 27 |
}; |
| 28 |
|
| 29 |
struct Value { |
| 30 |
_Bool b; |
| 31 |
char c; |
| 32 |
signed char sc; |
| 33 |
unsigned char uc; |
| 34 |
short ss; |
| 35 |
unsigned short us; |
| 36 |
int si; |
| 37 |
unsigned int ui; |
| 38 |
long sl; |
| 39 |
unsigned long ul; |
| 40 |
long long sll; |
| 41 |
unsigned long long ull; |
| 42 |
__SIZE_TYPE__ sz; |
| 43 |
}; |
| 44 |
|
| 45 |
/* Exercise the atomic_init() macro with a literal argument. */ |
| 46 |
|
| 47 |
void atomic_init_lit (struct Atomic *pa) |
| 48 |
{ |
| 49 |
atomic_init (&pa->b, 0); |
| 50 |
atomic_init (&pa->b, 1); |
| 51 |
|
| 52 |
atomic_init (&pa->c, 'x'); |
| 53 |
atomic_init (&pa->c, 0); |
| 54 |
atomic_init (&pa->c, 1); |
| 55 |
atomic_init (&pa->c, 255); |
| 56 |
|
| 57 |
atomic_init (&pa->sc, (signed char)'x'); |
| 58 |
atomic_init (&pa->sc, (signed char)0); |
| 59 |
atomic_init (&pa->sc, (signed char)1); |
| 60 |
atomic_init (&pa->sc, (signed char)__SCHAR_MAX__); |
| 61 |
|
| 62 |
atomic_init (&pa->uc, (unsigned char)'x'); |
| 63 |
atomic_init (&pa->uc, (unsigned char)0); |
| 64 |
atomic_init (&pa->uc, (unsigned char)1); |
| 65 |
atomic_init (&pa->sc, (unsigned char)__SCHAR_MAX__); |
| 66 |
|
| 67 |
atomic_init (&pa->ss, (signed short)0); |
| 68 |
atomic_init (&pa->ss, (signed short)1); |
| 69 |
atomic_init (&pa->ss, (signed short)__SHRT_MAX__); |
| 70 |
|
| 71 |
atomic_init (&pa->us, (unsigned short)0); |
| 72 |
atomic_init (&pa->us, (unsigned short)1); |
| 73 |
atomic_init (&pa->us, (unsigned short)__SHRT_MAX__); |
| 74 |
|
| 75 |
atomic_init (&pa->si, (signed int)0); |
| 76 |
atomic_init (&pa->si, (signed int)1); |
| 77 |
atomic_init (&pa->si, (signed int)__INT_MAX__); |
| 78 |
|
| 79 |
atomic_init (&pa->ui, (unsigned int)0); |
| 80 |
atomic_init (&pa->ui, (unsigned int)1); |
| 81 |
atomic_init (&pa->ui, (unsigned int)__INT_MAX__); |
| 82 |
|
| 83 |
atomic_init (&pa->sl, (signed long)0); |
| 84 |
atomic_init (&pa->sl, (signed long)1); |
| 85 |
atomic_init (&pa->sl, (signed long)__LONG_MAX__); |
| 86 |
|
| 87 |
atomic_init (&pa->ul, (unsigned long)0); |
| 88 |
atomic_init (&pa->ul, (unsigned long)1); |
| 89 |
atomic_init (&pa->ul, (unsigned long)__LONG_MAX__); |
| 90 |
|
| 91 |
atomic_init (&pa->sll, (signed long long)0); |
| 92 |
atomic_init (&pa->sll, (signed long long)1); |
| 93 |
atomic_init (&pa->sll, (signed long long)__LONG_LONG_MAX__); |
| 94 |
|
| 95 |
atomic_init (&pa->ull, (unsigned long long)0); |
| 96 |
atomic_init (&pa->ull, (unsigned long long)1); |
| 97 |
atomic_init (&pa->ull, (unsigned long long)__LONG_LONG_MAX__); |
| 98 |
|
| 99 |
atomic_init (&pa->sz, 0); |
| 100 |
atomic_init (&pa->sz, 1); |
| 101 |
atomic_init (&pa->sz, __SIZE_MAX__); |
| 102 |
} |
| 103 |
|
| 104 |
/* Exercise the atomic_init() macro with an lvalue argument. */ |
| 105 |
|
| 106 |
void atomic_init_lval (struct Atomic *pa, const struct Value *pv) |
| 107 |
{ |
| 108 |
atomic_init (&pa->b, pv->b); |
| 109 |
atomic_init (&pa->c, pv->c); |
| 110 |
atomic_init (&pa->sc, pv->sc); |
| 111 |
atomic_init (&pa->uc, pv->uc); |
| 112 |
atomic_init (&pa->ss, pv->ss); |
| 113 |
atomic_init (&pa->us, pv->us); |
| 114 |
atomic_init (&pa->si, pv->si); |
| 115 |
atomic_init (&pa->ui, pv->ui); |
| 116 |
atomic_init (&pa->sl, pv->sl); |
| 117 |
atomic_init (&pa->ul, pv->ul); |
| 118 |
atomic_init (&pa->sll, pv->sll); |
| 119 |
atomic_init (&pa->ull, pv->ull); |
| 120 |
atomic_init (&pa->sz, pv->sz); |
| 121 |
} |