1 // RUN: %clang_cc1 -verify %s
4 * preprocessor arithmetic done in intmax_t/uintmax_t
7 // There is not a standard requirement that this relationships holds. If these
8 // asserts fail, it means we have another test scenario to consider.
9 _Static_assert(__INTMAX_MAX__
== __LONG_LONG_MAX__
,
10 "intmax_t is not the same width as long long?");
11 _Static_assert((-__INTMAX_MAX__
- 1) == (-__LONG_LONG_MAX__
- 1LL),
12 "intmax_t is not the same width as long long?");
13 _Static_assert(__UINTMAX_MAX__
== (__LONG_LONG_MAX__
* 2ULL + 1ULL),
14 "uintmax_t is not the same width as unsigned long long?");
16 // Test that arithmetic on the largest positive signed intmax_t works.
17 #if 9223372036854775807LL + 0LL != 9223372036854775807LL
22 #if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL
26 // Then test the same for unsigned
27 #if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL
31 // Test that unsigned overflow causes silent wraparound.
32 #if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0.
36 #if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF.
40 // Now test that signed arithmetic that pushes us over a limit is properly
42 #if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}}
45 #if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}}