1 /* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>. */
3 /* { dg-options "-std=c23" } */
7 #if __STDC_VERSION_STDCKDINT_H__ != 202311L
8 # error __STDC_VERSION_STDCKDINT_H__ not defined to 202311L
11 extern void abort (void);
17 if (ckd_add (&a
, 1, 2) || a
!= 3)
19 if (ckd_add (&a
, ~2U, 2) || a
!= ~0U)
21 if (!ckd_add (&a
, ~2U, 4) || a
!= 1)
23 if (ckd_sub (&a
, 42, 2) || a
!= 40)
25 if (!ckd_sub (&a
, 11, ~0ULL) || a
!= 12)
27 if (ckd_mul (&a
, 42, 16U) || a
!= 672)
29 if (ckd_mul (&a
, ~0UL, 0) || a
!= 0)
31 if (ckd_mul (&a
, 1, ~0U) || a
!= ~0U)
33 if (ckd_mul (&a
, ~0UL, 1) != (~0UL > ~0U) || a
!= ~0U)
35 static_assert (_Generic (ckd_add (&a
, 1, 1), bool: 1, default: 0));
36 static_assert (_Generic (ckd_sub (&a
, 1, 1), bool: 1, default: 0));
37 static_assert (_Generic (ckd_mul (&a
, 1, 1), bool: 1, default: 0));
39 if (ckd_add (&b
, 8, 12) || b
!= 20)
41 if (ckd_sub (&b
, 8UL, 12ULL) || b
!= -4)
43 if (ckd_mul (&b
, 2, 3) || b
!= 6)
46 if (ckd_add (&c
, 8, 12) || c
!= 20)
48 if (ckd_sub (&c
, 8UL, 12ULL) != (-4ULL > (unsigned char) -4U)
49 || c
!= (unsigned char) -4U)
51 if (ckd_mul (&c
, 2, 3) || c
!= 6)
54 if (ckd_add (&d
, ~0U, ~0U) != (~0U + 1ULL < ~0U)
55 || d
!= (long long) (2 * (unsigned long long) ~0U))
57 if (ckd_sub (&d
, 0, 0) || d
!= 0)
59 if (ckd_mul (&d
, 16, 1) || d
!= 16)