Debian Codegraph @

gcc/testsuite/g++.dg/template/builtin-atomic-overloads6.C

raw
1 /* Various atomic builtin errors are still emitted when in a fully specified
2 builtin in a template. */
3 // { dg-do compile { target c++17 } }
4 // { dg-additional-options "-Wno-pedantic" }
5 #include <type_traits>
6 #ifdef __ARM_FEATURE_SVE
7 #include <arm_sve.h>
8 #endif
9
10 /*
11 Covering all if clauses, *not* all possible errors.
12 E.g. load, store, exchange, compare_exchange all go through
13 get_atomic_generic_size. I ensure I test all if clauses in that function
14 but do not ensure each clause is hit when using each of the different
15 builtins.
16
17 This is the stuff that is not handled by
18 builtin-atomic-overloads{1,2,3,4,5}.C */
19
20 class X{};
21 /* Want a zero-sized type in order to trigger one of the error messages.
22 Don't want the error message about creating a zero sized type.
23 However, *do* want to see any pedantic error messages coming from the rest
24 of the testcase. */
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wpedantic"
27 class Zero {
28 unsigned int trailing[0];
29 };
30 #pragma GCC diagnostic pop
31 class Large { public: int arr[10]; };
32 class Incomplete;
33 /* If there are other non-constant size types that I can use in a template
34 would appreciate hearing about it (especially if they work on all targets).
35 AFAIK VLA's are the other canonical example and have not managed to trigger
36 the same error with those due to scoping limitations. */
37 #ifdef __ARM_FEATURE_SVE
38 typedef __SVUint32_t NonConstant;
39 #else
40 class NonConstant { };
41 #endif
42 typedef __UINT64_TYPE__ uint64_t;
43 typedef __UINT32_TYPE__ uint32_t;
44 // typedef _BitInt(12) Bitint;
45
46
47 #define INCORRECT_NUMBER_ARGUMENTS(X) \
48 X(load, (int(), int(), int(), int()), 0)
49
50 #define NONPOINTER_FIRST_ARG(X) \
51 X(load, (int(), int(), int()), 1)
52 #define INCOMPLETE_FIRST_ARG(X) \
53 X(load, (Incomplete(), int(), int()), 2)
54 /* This won't trigger relevant fail when not using nonconstant sized type. */
55 #define NONCONST_SIZE_FIRST_ARG(X) \
56 X(load, (std::declval<NonConstant*>(), std::declval<NonConstant*>(), int()), 3)
57 #define ZEROSIZE_FIRST_ARG(X) \
58 X(load, (std::declval<Zero*>(), std::declval<Zero*>(), int()), 4)
59
60 // Errors triggered by a bad type in the first position not yet triggered by
61 // builtin-atomic-overloads5.C.
62 // These are already checked to *not* give an error in the SFINAE context by
63 // builtin-atomic-overloads1.C.
64 #define FIRST_ARGS_BADTYPE(X) \
65 ZEROSIZE_FIRST_ARG(X) \
66 NONCONST_SIZE_FIRST_ARG(X) \
67 INCOMPLETE_FIRST_ARG(X) \
68 NONPOINTER_FIRST_ARG(X)
69
70 #define NONPOINTER_OTHER_ARG(X) \
71 X(load, (std::declval<int*>(), int(), int()), 5)
72 /* This won't trigger relevant fail when not using nonconstant sized type. */
73 #define NONCONST_SIZE_OTHER_ARG(X) \
74 X(load, (std::declval<int*>(), std::declval<NonConstant*>(), int()), 6)
75 #define FUNCTIONPTR_OTHER_ARG(X) \
76 X(load, (std::declval<int*>(), std::declval<int(*)()>(), int()), 7)
77 #define SIZE_MISMATCH(X) \
78 X(load, (std::declval<uint32_t*>(), std::declval<uint64_t*>(), int()), 8)
79 #define OUTPUT_CONST(X) \
80 X(load, (std::declval<int*>(), std::declval<const int*>(), int()), 9)
81 #define SECOND_VOLATILE(X) \
82 X(load, (std::declval<int*>(), std::declval<volatile int*>(), int()), 10)
83
84 #define OTHER_ARG_BADTYPE(X) \
85 NONPOINTER_OTHER_ARG(X) \
86 SECOND_VOLATILE(X) \
87 OUTPUT_CONST(X) \
88 SIZE_MISMATCH(X) \
89 FUNCTIONPTR_OTHER_ARG(X) \
90 NONCONST_SIZE_OTHER_ARG(X)
91
92 #define MEMMODEL_BADTYPE(X) \
93 X(load, (std::declval<int*>(), std::declval<int*>(), float()), 11)
94 #define MEMMODEL_TOOLARGE(X) \
95 X(load, (std::declval<int*>(), std::declval<int*>(), 100), 12)
96
97 #define MEMMODEL_BAD(X) \
98 MEMMODEL_BADTYPE(X) \
99 MEMMODEL_TOOLARGE(X)
100
101 #define GET_ATOMIC_GENERIC_ERRS(X) \
102 INCORRECT_NUMBER_ARGUMENTS(X) \
103 FIRST_ARGS_BADTYPE(X) \
104 OTHER_ARG_BADTYPE(X) \
105 MEMMODEL_BAD(X)
106
107 #define SYNC_SIZE_TOOFEW(X) \
108 X(load_n, (), 0)
109 #define SYNC_SIZE_INCOMPATIBLE(X) \
110 X(load_n, (int(), int()), 1)
111 #define SYNC_SIZE_ERRS(X) \
112 SYNC_SIZE_TOOFEW(X) \
113 SYNC_SIZE_INCOMPATIBLE(X)
114
115 #define SYNC_PARM_TOOFEW(X) \
116 X(load_n, (std::declval<int*>()), 2)
117 #define SYNC_PARM_TOOMANY(X) \
118 X(load_n, (std::declval<int*>(), int(), int()), 3)
119 #define SYNC_PARM_ERRS(X) \
120 SYNC_PARM_TOOFEW(X) \
121 SYNC_PARM_TOOMANY(X)
122
123 /*
124 No Bitint in C++. Hence can't check for this error.
125 #define BITINT_FETCHCAS_TOOFEW(X) \
126 X(add_fetch, (std::declval<Bitint*>(), std::declval<Bitint>()))
127 #define BITINT_FETCHCAS_TOOMANY(X) \
128 X(add_fetch, (std::declval<Bitint*>(), std::declval<Bitint>(), int(), int()))
129 #define BITINT_FETCHCAS_ERRS(X) \
130 BITINT_FETCHCAS_TOOFEW(X) \
131 BITINT_FETCHCAS_TOOMANY(X)
132 */
133 #define BITINT_FETCHCAS_ERRS(X)
134
135 #define ALL_ERRS(X) \
136 GET_ATOMIC_GENERIC_ERRS(X) \
137 SYNC_SIZE_ERRS(X) \
138 SYNC_PARM_ERRS(X) \
139 BITINT_FETCHCAS_ERRS(X)
140
141 #define SFINAE_TYPE_CHECK(NAME, PARAMS, COUNTER) \
142 template <typename T, typename = void> \
143 struct is_##NAME##_available_##COUNTER : std::false_type {}; \
144 template <typename T> \
145 struct is_##NAME##_available_##COUNTER<T, \
146 std::void_t<decltype(__atomic_##NAME PARAMS) >> \
147 : std::true_type {}; \
148
149 ALL_ERRS(SFINAE_TYPE_CHECK)
150
151 /* { dg-error "too few arguments to function '__atomic_load_n'" "" { target *-*-* } 108 } */
152 /* { dg-error "operand type 'int' is incompatible with argument 1 of '__atomic_load_n'" "" { target *-*-* } 110 } */
153 /* { dg-error "too few arguments to function '__atomic_load_n'" "" { target *-*-* } 116 } */
154 /* { dg-error "too many arguments to function '__atomic_load_n'" "" { target *-*-* } 118 } */
155 /* { dg-error "template argument 1 is invalid" "" { target *-*-* } 146 } */
156 /* { dg-error "template argument 2 is invalid" "" { target *-*-* } 146 } */
157 /* { dg-error "incorrect number of arguments to function '__atomic_load'" "" { target *-*-* } 48 } */
158 /* { dg-error "argument 1 of '__atomic_load' must be a non-void pointer type" "" { target *-*-* } 51 } */
159 /* { dg-error "argument 1 of '__atomic_load' must be a non-void pointer type" "" { target *-*-* } 53 } */
160 /* { dg-error "argument 1 of '__atomic_load' must be a pointer to a constant size type" "" { target aarch64_sve } 56 } */
161 /* { dg-error "argument 1 of '__atomic_load' must be a pointer to a nonzero size object" "" { target *-*-* } 58 } */
162 /* { dg-error "argument 2 of '__atomic_load' must be a pointer type" "" { target *-*-* } 71 } */
163 /* { dg-error "argument 2 of '__atomic_load' must be a pointer to a constant size type" "" { target aarch64_sve } 74 } */
164 /* { dg-error "size mismatch in argument 2 of '__atomic_load'" "" { target { ! aarch64_sve } } 74 } */
165 /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a function" "" { target *-*-* } 76 } */
166 /* { dg-error "size mismatch in argument 2 of '__atomic_load'" "" { target *-*-* } 78 } */
167 /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a 'const' type" "" { target *-*-* } 80 } */
168 /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a 'volatile' type" "" { target *-*-* } 82 } */
169 /* { dg-error "non-integer memory model argument 3 of '__atomic_load'" "" { target *-*-* } 93 } */
170
171 /* { dg-warning {invalid memory model argument 3 of '__atomic_load' \[-Winvalid-memory-model\]} "" { target *-*-* } 95 } */