1 /* Test stdatomic.h header contents.  */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
4 
5 #include <stdatomic.h>
6 
7 #ifndef ATOMIC_BOOL_LOCK_FREE
8 # error ATOMIC_BOOL_LOCK_FREE not defined
9 #endif
10 
11 #ifndef ATOMIC_CHAR_LOCK_FREE
12 # error ATOMIC_CHAR_LOCK_FREE not defined
13 #endif
14 
15 #ifndef ATOMIC_CHAR16_T_LOCK_FREE
16 # error ATOMIC_CHAR16_T_LOCK_FREE not defined
17 #endif
18 
19 #ifndef ATOMIC_CHAR32_T_LOCK_FREE
20 # error ATOMIC_CHAR32_T_LOCK_FREE not defined
21 #endif
22 
23 #ifndef ATOMIC_WCHAR_T_LOCK_FREE
24 # error ATOMIC_WCHAR_T_LOCK_FREE not defined
25 #endif
26 
27 #ifndef ATOMIC_SHORT_LOCK_FREE
28 # error ATOMIC_SHORT_LOCK_FREE not defined
29 #endif
30 
31 #ifndef ATOMIC_INT_LOCK_FREE
32 # error ATOMIC_INT_LOCK_FREE not defined
33 #endif
34 
35 #ifndef ATOMIC_LONG_LOCK_FREE
36 # error ATOMIC_LONG_LOCK_FREE not defined
37 #endif
38 
39 #ifndef ATOMIC_LLONG_LOCK_FREE
40 # error ATOMIC_LLONG_LOCK_FREE not defined
41 #endif
42 
43 #ifndef ATOMIC_POINTER_LOCK_FREE
44 # error ATOMIC_POINTER_LOCK_FREE not defined
45 #endif
46 
47 memory_order m0 = memory_order_relaxed;
48 memory_order m1 = memory_order_consume;
49 memory_order m2 = memory_order_acquire;
50 memory_order m3 = memory_order_release;
51 memory_order m4 = memory_order_acq_rel;
52 memory_order m5 = memory_order_seq_cst;
53 
54 atomic_flag af = ATOMIC_FLAG_INIT;
55 
56 struct s { int i[100]; } sv;
57 void
f(void)58 f (void)
59 {
60   _Atomic struct s sva = ATOMIC_VAR_INIT (sv);
61 }
62 
63 #ifndef kill_dependency
64 # error kill_dependency not defined
65 #endif
66 
67 #define CHECK_ATOMIC_TYPEDEF(A, B)				\
68   do								\
69     {								\
70       A v;							\
71       char array1[sizeof (A) == sizeof (B) ? 1 : -1];		\
72       char array2[_Alignof (A) == _Alignof (B) ? 1 : -1];	\
73     }								\
74   while (0)
75 
76 #include <stddef.h>
77 #include <stdint.h>
78 
79 void
check_typedefs(void)80 check_typedefs (void)
81 {
82   CHECK_ATOMIC_TYPEDEF (atomic_bool, _Atomic _Bool);
83   CHECK_ATOMIC_TYPEDEF (atomic_char, _Atomic char);
84   CHECK_ATOMIC_TYPEDEF (atomic_schar, _Atomic signed char);
85   CHECK_ATOMIC_TYPEDEF (atomic_uchar, _Atomic unsigned char);
86   CHECK_ATOMIC_TYPEDEF (atomic_short, _Atomic short);
87   CHECK_ATOMIC_TYPEDEF (atomic_ushort, _Atomic unsigned short);
88   CHECK_ATOMIC_TYPEDEF (atomic_int, _Atomic int);
89   CHECK_ATOMIC_TYPEDEF (atomic_uint, _Atomic unsigned int);
90   CHECK_ATOMIC_TYPEDEF (atomic_long, _Atomic long);
91   CHECK_ATOMIC_TYPEDEF (atomic_ulong, _Atomic unsigned long);
92   CHECK_ATOMIC_TYPEDEF (atomic_llong, _Atomic long long);
93   CHECK_ATOMIC_TYPEDEF (atomic_ullong, _Atomic unsigned long long);
94   CHECK_ATOMIC_TYPEDEF (atomic_char16_t, _Atomic __CHAR16_TYPE__);
95   CHECK_ATOMIC_TYPEDEF (atomic_char32_t, _Atomic __CHAR32_TYPE__);
96   CHECK_ATOMIC_TYPEDEF (atomic_wchar_t, _Atomic wchar_t);
97   CHECK_ATOMIC_TYPEDEF (atomic_int_least8_t, _Atomic int_least8_t);
98   CHECK_ATOMIC_TYPEDEF (atomic_uint_least8_t, _Atomic uint_least8_t);
99   CHECK_ATOMIC_TYPEDEF (atomic_int_least16_t, _Atomic int_least16_t);
100   CHECK_ATOMIC_TYPEDEF (atomic_uint_least16_t, _Atomic uint_least16_t);
101   CHECK_ATOMIC_TYPEDEF (atomic_int_least32_t, _Atomic int_least32_t);
102   CHECK_ATOMIC_TYPEDEF (atomic_uint_least32_t, _Atomic uint_least32_t);
103   CHECK_ATOMIC_TYPEDEF (atomic_int_least64_t, _Atomic int_least64_t);
104   CHECK_ATOMIC_TYPEDEF (atomic_uint_least64_t, _Atomic uint_least64_t);
105   CHECK_ATOMIC_TYPEDEF (atomic_int_fast8_t, _Atomic int_fast8_t);
106   CHECK_ATOMIC_TYPEDEF (atomic_uint_fast8_t, _Atomic uint_fast8_t);
107   CHECK_ATOMIC_TYPEDEF (atomic_int_fast16_t, _Atomic int_fast16_t);
108   CHECK_ATOMIC_TYPEDEF (atomic_uint_fast16_t, _Atomic uint_fast16_t);
109   CHECK_ATOMIC_TYPEDEF (atomic_int_fast32_t, _Atomic int_fast32_t);
110   CHECK_ATOMIC_TYPEDEF (atomic_uint_fast32_t, _Atomic uint_fast32_t);
111   CHECK_ATOMIC_TYPEDEF (atomic_int_fast64_t, _Atomic int_fast64_t);
112   CHECK_ATOMIC_TYPEDEF (atomic_uint_fast64_t, _Atomic uint_fast64_t);
113   CHECK_ATOMIC_TYPEDEF (atomic_intptr_t, _Atomic intptr_t);
114   CHECK_ATOMIC_TYPEDEF (atomic_uintptr_t, _Atomic uintptr_t);
115   CHECK_ATOMIC_TYPEDEF (atomic_size_t, _Atomic size_t);
116   CHECK_ATOMIC_TYPEDEF (atomic_ptrdiff_t, _Atomic ptrdiff_t);
117   CHECK_ATOMIC_TYPEDEF (atomic_intmax_t, _Atomic intmax_t);
118   CHECK_ATOMIC_TYPEDEF (atomic_uintmax_t, _Atomic uintmax_t);
119 }
120