1 /* PR c/68120 - can't easily deal with integer overflow at compile time */
3 /* { dg-additional-options "-Wno-long-long" } */
4 /* { dg-skip-if "Program too big" { "avr-*-*" } } */
6 #define SCHAR_MAX __SCHAR_MAX__
7 #define SHRT_MAX __SHRT_MAX__
8 #define INT_MAX __INT_MAX__
9 #define LONG_MAX __LONG_MAX__
10 #define LLONG_MAX __LONG_LONG_MAX__
12 #define SCHAR_MIN (-__SCHAR_MAX__ - 1)
13 #define SHRT_MIN (-__SHRT_MAX__ - 1)
14 #define INT_MIN (-__INT_MAX__ - 1)
15 #define LONG_MIN (-__LONG_MAX__ - 1)
16 #define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
18 #define UCHAR_MAX (SCHAR_MAX * 2U + 1)
19 #define USHRT_MAX (SHRT_MAX * 2U + 1)
20 #define UINT_MAX (INT_MAX * 2U + 1)
21 #define ULONG_MAX (LONG_MAX * 2LU + 1)
22 #define ULLONG_MAX (LLONG_MAX * 2LLU + 1)
24 #define USCHAR_MIN (-__USCHAR_MAX__ - 1)
25 #define USHRT_MIN (-__USHRT_MAX__ - 1)
26 #define UINT_MIN (-__UINT_MAX__ - 1)
27 #define ULONG_MIN (-__ULONG_MAX__ - 1)
28 #define ULLONG_MIN (-__ULONG_LONG_MAX__ - 1)
30 /* Number of failed runtime assertions. */
33 void __attribute__ ((noclone
, noinline
))
34 runtime_assert (int expr
, int line
)
38 __builtin_printf ("line %i: assertion failed\n", line
);
43 /* Helper macros for run-time testing. */
44 #define add(x, y) ((x) + (y))
45 #define sadd(x, y) ((x) + (y))
46 #define saddl(x, y) ((x) + (y))
47 #define saddll(x, y) ((x) + (y))
48 #define uadd(x, y) ((x) + (y))
49 #define uaddl(x, y) ((x) + (y))
50 #define uaddll(x, y) ((x) + (y))
51 #define sub(x, y) ((x) - (y))
52 #define ssub(x, y) ((x) - (y))
53 #define ssubl(x, y) ((x) - (y))
54 #define ssubll(x, y) ((x) - (y))
55 #define usub(x, y) ((x) - (y))
56 #define usubl(x, y) ((x) - (y))
57 #define usubll(x, y) ((x) - (y))
58 #define mul(x, y) ((x) * (y))
59 #define smul(x, y) ((x) * (y))
60 #define smull(x, y) ((x) * (y))
61 #define smulll(x, y) ((x) * (y))
62 #define umul(x, y) ((x) * (y))
63 #define umull(x, y) ((x) * (y))
64 #define umulll(x, y) ((x) * (y))
69 #if __cplusplus >= 201103L
70 # define StaticAssert(expr) static_assert ((expr), #expr)
71 #elif __STDC_VERSION__ >= 201112L
72 # define StaticAssert(expr) _Static_assert ((expr), #expr)
74 /* The following pragma has no effect due to bug 70888 - #pragma
75 diagnostic ignored -Wlong-long ineffective with __LONG_LONG_MAX__
77 # pragma GCC diagnostic ignored "-Wlong-long"
78 # pragma GCC diagnostic ignored "-Wunused-local-typedefs"
80 # define CONCAT(a, b) a ## b
81 # define CAT(a, b) CONCAT (a, b)
82 # define StaticAssert(expr) \
83 typedef int CAT (StaticAssert_, __LINE__) [1 - 2 * !(expr)]
86 /* Make extra effort to prevent constant folding seeing the constant
87 values of the arguments and optimizing the run-time test into
89 #define RuntimeAssert(op, T, U, x, y, vflow) \
91 volatile T a = (x), b = (y); \
93 volatile int vf = __builtin_ ## op ## _overflow (a, b, &c); \
94 runtime_assert ((vf == vflow), __LINE__); \
96 runtime_assert (op (a, b) == c, __LINE__); \
99 /* Verify that each call to the type-generic __builtin_op_overflow(x, y)
100 yields a constant expression equal to z indicating whether or not
101 the constant expression (x op y) overflows when evaluated in type T. */
102 # define G_TEST(op, T, x, y, vflow) \
103 RuntimeAssert(op, __typeof__ (op (x, y)), T, x, y, vflow); \
104 StaticAssert ((vflow) == __builtin_ ## op ## _overflow_p ((x), (y), (T)0))
107 G_TEST (add
, signed char, 0, 0, 0);
108 G_TEST (add
, signed char, 0, SCHAR_MAX
, 0);
109 G_TEST (add
, signed char, 1, SCHAR_MAX
, 1);
110 G_TEST (add
, signed char, SCHAR_MAX
, SCHAR_MAX
, 1);
111 G_TEST (add
, signed char, 0, SCHAR_MIN
, 0);
112 G_TEST (add
, signed char, -1, SCHAR_MIN
, 1);
113 /* Verify any slicing in the result type doesn't prevent the overflow
114 from being detected. */
115 G_TEST (add
, signed char, UCHAR_MAX
+ 1, 0, 1);
116 G_TEST (add
, signed char, UCHAR_MAX
+ 1, 1, 1);
117 G_TEST (add
, signed char, 1, UCHAR_MAX
+ 1, 1);
119 G_TEST (add
, unsigned char, 0, 0, 0);
120 /* Verify any slicing in the result type doesn't prevent the overflow
121 from being detected. */
122 G_TEST (add
, unsigned char, UCHAR_MAX
+ 1, 0, 1);
123 G_TEST (add
, unsigned char, UCHAR_MAX
+ 1, 1, 1);
124 G_TEST (add
, unsigned char, 1, UCHAR_MAX
+ 1, 1);
126 G_TEST (add
, short, 0, 0, 0);
127 G_TEST (add
, short, 0, SHRT_MAX
, 0);
128 G_TEST (add
, short, 1, SHRT_MAX
, 1);
129 G_TEST (add
, short, SHRT_MAX
, SHRT_MAX
, 1);
130 G_TEST (add
, short, 0, SHRT_MIN
, 0);
131 G_TEST (add
, short, -1, SHRT_MIN
, 1);
132 G_TEST (add
, short, SHRT_MIN
, SHRT_MIN
, 1);
134 G_TEST (add
, int, 0, 0, 0);
135 G_TEST (add
, int, 0, INT_MAX
, 0);
136 G_TEST (add
, int, 1, INT_MAX
, 1);
137 G_TEST (add
, int, INT_MAX
, INT_MAX
, 1);
138 G_TEST (add
, int, 0, INT_MIN
, 0);
139 G_TEST (add
, int, -1, INT_MIN
, 1);
140 G_TEST (add
, int, INT_MIN
, INT_MIN
, 1);
142 G_TEST (add
, long, 0, 0, 0);
143 G_TEST (add
, long, 0, LONG_MAX
, 0);
144 G_TEST (add
, long, 1, LONG_MAX
, 1);
145 G_TEST (add
, long, LONG_MAX
, LONG_MAX
, 1);
146 G_TEST (add
, long, 0, LONG_MIN
, 0);
147 G_TEST (add
, long, -1, LONG_MIN
, 1);
148 G_TEST (add
, long, LONG_MIN
, LONG_MIN
, 1);
150 G_TEST (add
, long long, 0, 0, 0);
151 G_TEST (add
, long long, 0, LLONG_MAX
, 0);
152 G_TEST (add
, long long, 1, LLONG_MAX
, 1);
153 G_TEST (add
, long long, LLONG_MAX
, LLONG_MAX
, 1);
154 G_TEST (add
, long long, 0, LLONG_MIN
, 0);
155 G_TEST (add
, long long, -1, LLONG_MIN
, 1);
156 G_TEST (add
, long long, LLONG_MIN
, LLONG_MIN
, 1);
159 G_TEST (sub
, unsigned char, 0, 0, 0);
160 G_TEST (sub
, unsigned char, 0, UCHAR_MAX
, 1);
161 G_TEST (sub
, unsigned char, 1, UCHAR_MAX
, 1);
163 G_TEST (sub
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 0);
164 G_TEST (sub
, unsigned short, 0, 0, 0);
165 G_TEST (sub
, unsigned short, 0, USHRT_MAX
, 1);
166 G_TEST (sub
, unsigned short, 1, USHRT_MAX
, 1);
167 G_TEST (sub
, unsigned short, USHRT_MAX
, USHRT_MAX
, 0);
169 G_TEST (sub
, unsigned, 0, 0, 0);
170 G_TEST (sub
, unsigned, 0, UINT_MAX
, 1);
171 G_TEST (sub
, unsigned, 1, UINT_MAX
, 1);
172 G_TEST (sub
, unsigned, UINT_MAX
, UINT_MAX
, 0);
174 G_TEST (sub
, unsigned long, 0, 0, 0);
175 G_TEST (sub
, unsigned long, 0, ULONG_MAX
, 1);
176 G_TEST (sub
, unsigned long, 1, ULONG_MAX
, 1);
177 G_TEST (sub
, unsigned long, ULONG_MAX
, ULONG_MAX
, 0);
179 G_TEST (sub
, unsigned long long, 0, 0, 0);
180 G_TEST (sub
, unsigned long long, 0, ULLONG_MAX
, 1);
181 G_TEST (sub
, unsigned long long, 1, ULLONG_MAX
, 1);
182 G_TEST (sub
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 0);
184 G_TEST (sub
, signed char, 0, 0, 0);
185 G_TEST (sub
, signed char, 0, SCHAR_MAX
, 0);
186 G_TEST (sub
, signed char, 1, SCHAR_MAX
, 0);
187 G_TEST (sub
, signed char, SCHAR_MAX
, SCHAR_MAX
, 0);
188 G_TEST (sub
, signed char, SCHAR_MIN
, 1, 1);
189 G_TEST (sub
, signed char, 0, SCHAR_MIN
, 1);
190 G_TEST (sub
, signed char, -1, SCHAR_MIN
, 0);
192 G_TEST (sub
, short, 0, 0, 0);
193 G_TEST (sub
, short, 0, SHRT_MAX
, 0);
194 G_TEST (sub
, short, 1, SHRT_MAX
, 0);
195 G_TEST (sub
, short, SHRT_MAX
, SHRT_MAX
, 0);
196 G_TEST (sub
, short, 0, SHRT_MIN
, 1);
197 G_TEST (sub
, short, -1, SHRT_MIN
, 0);
198 G_TEST (sub
, short, SHRT_MIN
, SHRT_MIN
, 0);
200 G_TEST (sub
, int, 0, 0, 0);
201 G_TEST (sub
, int, 0, INT_MAX
, 0);
202 G_TEST (sub
, int, 1, INT_MAX
, 0);
203 G_TEST (sub
, int, INT_MAX
, INT_MAX
, 0);
204 G_TEST (sub
, int, 0, INT_MIN
, 1);
205 G_TEST (sub
, int, -1, INT_MIN
, 0);
206 G_TEST (sub
, int, INT_MIN
, INT_MIN
, 0);
208 G_TEST (sub
, long, 0, 0, 0);
209 G_TEST (sub
, long, 0, LONG_MAX
, 0);
210 G_TEST (sub
, long, 1, LONG_MAX
, 0);
211 G_TEST (sub
, long, LONG_MAX
, LONG_MAX
, 0);
212 G_TEST (sub
, long, 0, LONG_MIN
, 1);
213 G_TEST (sub
, long, -1, LONG_MIN
, 0);
214 G_TEST (sub
, long, LONG_MIN
, LONG_MIN
, 0);
216 G_TEST (sub
, long long, 0, 0, 0);
217 G_TEST (sub
, long long, 0, LLONG_MAX
, 0);
218 G_TEST (sub
, long long, 1, LLONG_MAX
, 0);
219 G_TEST (sub
, long long, LLONG_MAX
, LLONG_MAX
, 0);
220 G_TEST (sub
, long long, 0, LLONG_MIN
, 1);
221 G_TEST (sub
, long long, -1, LLONG_MIN
, 0);
222 G_TEST (sub
, long long, LLONG_MIN
, LLONG_MIN
, 0);
224 G_TEST (sub
, unsigned char, 0, 0, 0);
225 G_TEST (sub
, unsigned char, 0, UCHAR_MAX
, 1);
226 G_TEST (sub
, unsigned char, 1, UCHAR_MAX
, 1);
227 G_TEST (sub
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 0);
229 G_TEST (sub
, unsigned short, 0, 0, 0);
230 G_TEST (sub
, unsigned short, 0, USHRT_MAX
, 1);
231 G_TEST (sub
, unsigned short, 1, USHRT_MAX
, 1);
232 G_TEST (sub
, unsigned short, USHRT_MAX
, USHRT_MAX
, 0);
234 G_TEST (sub
, unsigned, 0, 0, 0);
235 G_TEST (sub
, unsigned, 0, UINT_MAX
, 1);
236 G_TEST (sub
, unsigned, 1, UINT_MAX
, 1);
237 G_TEST (sub
, unsigned, UINT_MAX
, UINT_MAX
, 0);
239 G_TEST (sub
, unsigned long, 0, 0, 0);
240 G_TEST (sub
, unsigned long, 0, ULONG_MAX
, 1);
241 G_TEST (sub
, unsigned long, 1, ULONG_MAX
, 1);
242 G_TEST (sub
, unsigned long, ULONG_MAX
, ULONG_MAX
, 0);
244 G_TEST (sub
, unsigned long long, 0, 0, 0);
245 G_TEST (sub
, unsigned long long, 0, ULLONG_MAX
, 1);
246 G_TEST (sub
, unsigned long long, 1, ULLONG_MAX
, 1);
247 G_TEST (sub
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 0);
249 /* Multiplication. */
250 G_TEST (mul
, unsigned char, 0, 0, 0);
251 G_TEST (mul
, unsigned char, 0, UCHAR_MAX
, 0);
252 G_TEST (mul
, unsigned char, 1, UCHAR_MAX
, 0);
253 G_TEST (mul
, unsigned char, 2, UCHAR_MAX
, 1);
254 G_TEST (mul
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 1);
256 G_TEST (mul
, unsigned short, 0, 0, 0);
257 G_TEST (mul
, unsigned short, 0, USHRT_MAX
, 0);
258 G_TEST (mul
, unsigned short, 1, USHRT_MAX
, 0);
259 G_TEST (mul
, unsigned short, USHRT_MAX
, 2, 1);
260 G_TEST (mul
, unsigned short, USHRT_MAX
, USHRT_MAX
, 1);
262 G_TEST (mul
, unsigned, 0, 0, 0);
263 G_TEST (mul
, unsigned, 0, UINT_MAX
, 0);
264 G_TEST (mul
, unsigned, 1, UINT_MAX
, 0);
265 G_TEST (mul
, unsigned, 2, UINT_MAX
, 1);
266 G_TEST (mul
, unsigned, UINT_MAX
, UINT_MAX
, 1);
268 G_TEST (mul
, unsigned long, 0, 0, 0);
269 G_TEST (mul
, unsigned long, 0, ULONG_MAX
, 0);
270 G_TEST (mul
, unsigned long, 1, ULONG_MAX
, 0);
271 G_TEST (mul
, unsigned long, 2, ULONG_MAX
, 1);
272 G_TEST (mul
, unsigned long, ULONG_MAX
, ULONG_MAX
, 1);
274 G_TEST (mul
, unsigned long long, 0, 0, 0);
275 G_TEST (mul
, unsigned long long, 0, ULLONG_MAX
, 0);
276 G_TEST (mul
, unsigned long long, 1, ULLONG_MAX
, 0);
277 G_TEST (mul
, unsigned long long, 2, ULLONG_MAX
, 1);
278 G_TEST (mul
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 1);
280 G_TEST (mul
, signed char, 0, 0, 0);
281 G_TEST (mul
, signed char, 0, SCHAR_MAX
, 0);
282 G_TEST (mul
, signed char, 1, SCHAR_MAX
, 0);
283 G_TEST (mul
, signed char, SCHAR_MAX
, SCHAR_MAX
, 1);
284 G_TEST (mul
, signed char, SCHAR_MIN
, 1, 0);
285 G_TEST (mul
, signed char, 0, SCHAR_MIN
, 0);
286 G_TEST (mul
, signed char, -1, SCHAR_MIN
, 1);
288 G_TEST (mul
, short, 0, 0, 0);
289 G_TEST (mul
, short, 0, SHRT_MAX
, 0);
290 G_TEST (mul
, short, 1, SHRT_MAX
, 0);
291 G_TEST (mul
, short, SHRT_MAX
, SHRT_MAX
, 1);
292 G_TEST (mul
, short, 0, SHRT_MIN
, 0);
293 G_TEST (mul
, short, -1, SHRT_MIN
, 1);
294 G_TEST (mul
, short, SHRT_MIN
, SHRT_MIN
, 1);
296 G_TEST (mul
, int, 0, 0, 0);
297 G_TEST (mul
, int, 0, INT_MAX
, 0);
298 G_TEST (mul
, int, 1, INT_MAX
, 0);
299 G_TEST (mul
, int, INT_MAX
, INT_MAX
, 1);
300 G_TEST (mul
, int, 0, INT_MIN
, 0);
301 G_TEST (mul
, int, -1, INT_MIN
, 1);
302 G_TEST (mul
, int, INT_MIN
, INT_MIN
, 1);
304 G_TEST (mul
, long, 0, 0, 0);
305 G_TEST (mul
, long, 0, LONG_MAX
, 0);
306 G_TEST (mul
, long, 1, LONG_MAX
, 0);
307 G_TEST (mul
, long, LONG_MAX
, LONG_MAX
, 1);
308 G_TEST (mul
, long, 0, LONG_MIN
, 0);
309 G_TEST (mul
, long, -1, LONG_MIN
, 1);
310 G_TEST (mul
, long, LONG_MIN
, LONG_MIN
, 1);
312 G_TEST (mul
, long long, 0, 0, 0);
313 G_TEST (mul
, long long, 0, LLONG_MAX
, 0);
314 G_TEST (mul
, long long, 1, LLONG_MAX
, 0);
315 G_TEST (mul
, long long, LLONG_MAX
, LLONG_MAX
, 1);
316 G_TEST (mul
, long long, 0, LLONG_MIN
, 0);
317 G_TEST (mul
, long long, -1, LLONG_MIN
, 1);
318 G_TEST (mul
, long long, LLONG_MIN
, LLONG_MIN
, 1);
320 G_TEST (mul
, unsigned char, 0, 0, 0);
321 G_TEST (mul
, unsigned char, 0, UCHAR_MAX
, 0);
322 G_TEST (mul
, unsigned char, 1, UCHAR_MAX
, 0);
323 G_TEST (mul
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 1);
325 G_TEST (mul
, unsigned short, 0, 0, 0);
326 G_TEST (mul
, unsigned short, 0, USHRT_MAX
, 0);
327 G_TEST (mul
, unsigned short, 1, USHRT_MAX
, 0);
328 G_TEST (mul
, unsigned short, USHRT_MAX
, USHRT_MAX
, 1);
330 G_TEST (mul
, unsigned, 0, 0, 0);
331 G_TEST (mul
, unsigned, 0, UINT_MAX
, 0);
332 G_TEST (mul
, unsigned, 1, UINT_MAX
, 0);
333 G_TEST (mul
, unsigned, UINT_MAX
, UINT_MAX
, 1);
335 G_TEST (mul
, unsigned long, 0, 0, 0);
336 G_TEST (mul
, unsigned long, 0, ULONG_MAX
, 0);
337 G_TEST (mul
, unsigned long, 1, ULONG_MAX
, 0);
338 G_TEST (mul
, unsigned long, ULONG_MAX
, ULONG_MAX
, 1);
340 G_TEST (mul
, unsigned long long, 0, 0, 0);
341 G_TEST (mul
, unsigned long long, 0, ULLONG_MAX
, 0);
342 G_TEST (mul
, unsigned long long, 1, ULLONG_MAX
, 0);
343 G_TEST (mul
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 1);
345 /* Verify that each call to the type-specific __builtin_op_overflow
346 evaluates to a (not-necessarily constant) expression indicating
347 whether or not the constant expression (x op y) overflows.
348 The type-specific forms of the built-ins detect overflow after
349 arithmetic promotions and so unlike the type-generic overloads
350 cannot detect overflow in char or short types. */
352 #define T_TEST(op, T, x, y, vflow) \
353 RuntimeAssert (op, T, __typeof__ ((x) + (y)), x, y, vflow)
355 /* Signed int addition. */
356 T_TEST (sadd
, signed char, 0, 0, 0);
357 T_TEST (sadd
, signed char, 0, SCHAR_MAX
, 0);
358 T_TEST (sadd
, signed char, 1, SCHAR_MAX
, 0);
359 T_TEST (sadd
, signed char, SCHAR_MAX
, SCHAR_MAX
, 0);
360 T_TEST (sadd
, signed char, 0, SCHAR_MIN
, 0);
361 T_TEST (sadd
, signed char, -1, SCHAR_MIN
, 0);
363 T_TEST (sadd
, short, 0, 0, 0);
364 T_TEST (sadd
, short, 0, SHRT_MAX
, 0);
365 T_TEST (sadd
, short, 1, SHRT_MAX
, 0);
366 T_TEST (sadd
, short, SHRT_MAX
, SHRT_MAX
, 0);
367 T_TEST (sadd
, short, 0, SHRT_MIN
, 0);
368 T_TEST (sadd
, short, -1, SHRT_MIN
, 0);
369 T_TEST (sadd
, short, SHRT_MIN
, SHRT_MIN
, 0);
371 T_TEST (sadd
, int, 0, 0, 0);
372 T_TEST (sadd
, int, 0, INT_MAX
, 0);
373 T_TEST (sadd
, int, 1, INT_MAX
, 1);
374 T_TEST (sadd
, int, INT_MAX
, INT_MAX
, 1);
375 T_TEST (sadd
, int, 0, INT_MIN
, 0);
376 T_TEST (sadd
, int, -1, INT_MIN
, 1);
377 T_TEST (sadd
, int, INT_MIN
, INT_MIN
, 1);
379 /* Signed long addition. */
380 T_TEST (saddl
, long, 0L, 0L, 0);
381 T_TEST (saddl
, long, 0L, LONG_MAX
, 0);
382 T_TEST (saddl
, long, 1L, LONG_MAX
, 1);
383 T_TEST (saddl
, long, LONG_MAX
, LONG_MAX
, 1);
384 T_TEST (saddl
, long, 0L, LONG_MIN
, 0);
385 T_TEST (saddl
, long, -1L, LONG_MIN
, 1);
386 T_TEST (saddl
, long, LONG_MIN
, LONG_MIN
, 1);
388 T_TEST (saddll
, long long, 0LL, 0LL, 0);
389 T_TEST (saddll
, long long, 0LL, LLONG_MAX
, 0);
390 T_TEST (saddll
, long long, 1LL, LLONG_MAX
, 1);
391 T_TEST (saddll
, long long, LLONG_MAX
, LLONG_MAX
, 1);
392 T_TEST (saddll
, long long, 0LL, LLONG_MIN
, 0);
393 T_TEST (saddll
, long long, -1LL, LLONG_MIN
, 1);
394 T_TEST (saddll
, long long, LLONG_MIN
, LLONG_MIN
, 1);
396 /* Unsigned int addition. */
397 T_TEST (uadd
, unsigned char, 0U, 0U, 0);
398 T_TEST (uadd
, unsigned char, 0U, UCHAR_MAX
, 0);
399 T_TEST (uadd
, unsigned char, 1U, UCHAR_MAX
, 0);
400 T_TEST (uadd
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 0);
402 T_TEST (uadd
, unsigned short, 0U, 0U, 0);
403 T_TEST (uadd
, unsigned short, 0U, USHRT_MAX
, 0);
404 T_TEST (uadd
, unsigned short, 1U, USHRT_MAX
, 0);
405 T_TEST (uadd
, unsigned short, USHRT_MAX
, USHRT_MAX
, 0);
407 T_TEST (uadd
, unsigned, 0U, 0U, 0);
408 T_TEST (uadd
, unsigned, 0U, UINT_MAX
, 0);
409 T_TEST (uadd
, unsigned, 1U, UINT_MAX
, 1);
410 T_TEST (uadd
, unsigned, UINT_MAX
, UINT_MAX
, 1);
412 /* Unsigned long addition. */
413 T_TEST (uaddl
, unsigned long, 0UL, 0UL, 0);
414 T_TEST (uaddl
, unsigned long, 0UL, ULONG_MAX
, 0);
415 T_TEST (uaddl
, unsigned long, 1UL, ULONG_MAX
, 1);
416 T_TEST (uaddl
, unsigned long, ULONG_MAX
, ULONG_MAX
, 1);
418 T_TEST (uaddll
, unsigned long long, 0ULL, 0ULL, 0);
419 T_TEST (uaddll
, unsigned long long, 0ULL, ULLONG_MAX
, 0);
420 T_TEST (uaddll
, unsigned long long, 1ULL, ULLONG_MAX
, 1);
421 T_TEST (uaddll
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 1);
423 /* Signed int subtraction. */
424 T_TEST (ssub
, signed char, 0, 0, 0);
425 T_TEST (ssub
, signed char, 0, SCHAR_MAX
, 0);
426 T_TEST (ssub
, signed char, 1, SCHAR_MAX
, 0);
427 T_TEST (ssub
, signed char, SCHAR_MAX
, SCHAR_MAX
, 0);
428 T_TEST (ssub
, signed char, 0, SCHAR_MIN
, 0);
429 T_TEST (ssub
, signed char, -1, SCHAR_MIN
, 0);
431 T_TEST (ssub
, short, 0, 0, 0);
432 T_TEST (ssub
, short, 0, SHRT_MAX
, 0);
433 T_TEST (ssub
, short, 1, SHRT_MAX
, 0);
434 T_TEST (ssub
, short, SHRT_MAX
, SHRT_MAX
, 0);
435 T_TEST (ssub
, short, 0, SHRT_MIN
, 0);
436 T_TEST (ssub
, short, -1, SHRT_MIN
, 0);
437 T_TEST (ssub
, short, SHRT_MIN
, SHRT_MIN
, 0);
439 T_TEST (ssub
, int, 0, 0, 0);
440 T_TEST (ssub
, int, 0, INT_MAX
, 0);
441 T_TEST (ssub
, int, 1, INT_MAX
, 0);
442 T_TEST (ssub
, int, INT_MAX
, INT_MAX
, 0);
443 T_TEST (ssub
, int, 0, INT_MIN
, 1);
444 T_TEST (ssub
, int, -1, INT_MIN
, 0);
445 T_TEST (ssub
, int, INT_MIN
, INT_MIN
, 0);
447 /* Signed long subtraction. */
448 T_TEST (ssubl
, long, 0L, 0L, 0);
449 T_TEST (ssubl
, long, 0L, LONG_MAX
, 0);
450 T_TEST (ssubl
, long, 1L, LONG_MAX
, 0);
451 T_TEST (ssubl
, long, LONG_MAX
, LONG_MAX
, 0);
452 T_TEST (ssubl
, long, 0L, LONG_MIN
, 1);
453 T_TEST (ssubl
, long, -1L, LONG_MIN
, 0);
454 T_TEST (ssubl
, long, LONG_MIN
, LONG_MIN
, 0);
456 /* Signed long long subtraction. */
457 T_TEST (ssubll
, long long, 0LL, 0LL, 0);
458 T_TEST (ssubll
, long long, 0LL, LLONG_MAX
, 0);
459 T_TEST (ssubll
, long long, 1LL, LLONG_MAX
, 0);
460 T_TEST (ssubll
, long long, LLONG_MAX
, LLONG_MAX
, 0);
461 T_TEST (ssubll
, long long, 0LL, LLONG_MIN
, 1);
462 T_TEST (ssubll
, long long, -1LL, LLONG_MIN
, 0);
463 T_TEST (ssubll
, long long, LLONG_MIN
, LLONG_MIN
, 0);
465 /* Unsigned int subtraction. */
466 T_TEST (usub
, unsigned char, 0U, 0U, 0);
467 T_TEST (usub
, unsigned char, 0U, UCHAR_MAX
, 1);
468 T_TEST (usub
, unsigned char, 1U, UCHAR_MAX
, 1);
469 T_TEST (usub
, unsigned char, UCHAR_MAX
, UCHAR_MAX
, 0);
471 T_TEST (usub
, unsigned short, 0U, 0U, 0);
472 T_TEST (usub
, unsigned short, 0U, USHRT_MAX
, 1);
473 T_TEST (usub
, unsigned short, 1U, USHRT_MAX
, 1);
474 T_TEST (usub
, unsigned short, USHRT_MAX
, USHRT_MAX
, 0);
476 T_TEST (usub
, unsigned, 0U, 0U, 0);
477 T_TEST (usub
, unsigned, 0U, UINT_MAX
, 1);
478 T_TEST (usub
, unsigned, 1U, UINT_MAX
, 1);
479 T_TEST (usub
, unsigned, UINT_MAX
, UINT_MAX
, 0);
481 /* Unsigned long subtraction. */
482 T_TEST (usubl
, unsigned long, 0UL, 0UL, 0);
483 T_TEST (usubl
, unsigned long, 0UL, ULONG_MAX
, 1);
484 T_TEST (usubl
, unsigned long, 1UL, ULONG_MAX
, 1);
485 T_TEST (usubl
, unsigned long, ULONG_MAX
, ULONG_MAX
, 0);
487 /* Unsigned long long subtraction. */
488 T_TEST (usubll
, unsigned long long, 0ULL, 0ULL, 0);
489 T_TEST (usubll
, unsigned long long, 0ULL, ULLONG_MAX
, 1);
490 T_TEST (usubll
, unsigned long long, 1ULL, ULLONG_MAX
, 1);
491 T_TEST (usubll
, unsigned long long, ULLONG_MAX
, ULLONG_MAX
, 0);