File: n736.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (47 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// RUN: %clang_cc1 -verify %s

/* WG14 N736: yes
 * preprocessor arithmetic done in intmax_t/uintmax_t
 */

// There is not a standard requirement that this relationships holds. If these
// asserts fail, it means we have another test scenario to consider.
_Static_assert(__INTMAX_MAX__ == __LONG_LONG_MAX__,
               "intmax_t is not the same width as long long?");
_Static_assert((-__INTMAX_MAX__ - 1) == (-__LONG_LONG_MAX__ - 1LL),
               "intmax_t is not the same width as long long?");
_Static_assert(__UINTMAX_MAX__ == (__LONG_LONG_MAX__ * 2ULL + 1ULL),
               "uintmax_t is not the same width as unsigned long long?");

// Test that arithmetic on the largest positive signed intmax_t works.
#if 9223372036854775807LL + 0LL != 9223372036854775807LL
#error "uh oh"
#endif

// Same for negative.
#if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL
#error "uh oh"
#endif

// Then test the same for unsigned
#if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL
#error "uh oh"
#endif

// Test that unsigned overflow causes silent wraparound.
#if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0.
#error "uh oh"
#endif

#if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF.
#error "uh oh"
#endif

// Now test that signed arithmetic that pushes us over a limit is properly
// diagnosed.
#if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}}
#endif

#if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}}
#endif