Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / stdckdint-1.c
blobe104e686a4f692e44d39eb4c7101a6b6ed102eb0
1 /* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>. */
2 /* { dg-do run } */
3 /* { dg-options "-std=c23" } */
5 #include <stdckdint.h>
7 #if __STDC_VERSION_STDCKDINT_H__ != 202311L
8 # error __STDC_VERSION_STDCKDINT_H__ not defined to 202311L
9 #endif
11 extern void abort (void);
13 int
14 main ()
16 unsigned int a;
17 if (ckd_add (&a, 1, 2) || a != 3)
18 abort ();
19 if (ckd_add (&a, ~2U, 2) || a != ~0U)
20 abort ();
21 if (!ckd_add (&a, ~2U, 4) || a != 1)
22 abort ();
23 if (ckd_sub (&a, 42, 2) || a != 40)
24 abort ();
25 if (!ckd_sub (&a, 11, ~0ULL) || a != 12)
26 abort ();
27 if (ckd_mul (&a, 42, 16U) || a != 672)
28 abort ();
29 if (ckd_mul (&a, ~0UL, 0) || a != 0)
30 abort ();
31 if (ckd_mul (&a, 1, ~0U) || a != ~0U)
32 abort ();
33 if (ckd_mul (&a, ~0UL, 1) != (~0UL > ~0U) || a != ~0U)
34 abort ();
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));
38 signed char b;
39 if (ckd_add (&b, 8, 12) || b != 20)
40 abort ();
41 if (ckd_sub (&b, 8UL, 12ULL) || b != -4)
42 abort ();
43 if (ckd_mul (&b, 2, 3) || b != 6)
44 abort ();
45 unsigned char c;
46 if (ckd_add (&c, 8, 12) || c != 20)
47 abort ();
48 if (ckd_sub (&c, 8UL, 12ULL) != (-4ULL > (unsigned char) -4U)
49 || c != (unsigned char) -4U)
50 abort ();
51 if (ckd_mul (&c, 2, 3) || c != 6)
52 abort ();
53 long long d;
54 if (ckd_add (&d, ~0U, ~0U) != (~0U + 1ULL < ~0U)
55 || d != (long long) (2 * (unsigned long long) ~0U))
56 abort ();
57 if (ckd_sub (&d, 0, 0) || d != 0)
58 abort ();
59 if (ckd_mul (&d, 16, 1) || d != 16)
60 abort ();