1 // RUN: %clang_cc1 -verify %s 2 3 /* WG14 N736: yes 4 * preprocessor arithmetic done in intmax_t/uintmax_t 5 */ 6 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?"); 15 16 // Test that arithmetic on the largest positive signed intmax_t works. 17 #if 9223372036854775807LL + 0LL != 9223372036854775807LL 18 #error "uh oh" 19 #endif 20 21 // Same for negative. 22 #if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL 23 #error "uh oh" 24 #endif 25 26 // Then test the same for unsigned 27 #if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL 28 #error "uh oh" 29 #endif 30 31 // Test that unsigned overflow causes silent wraparound. 32 #if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0. 33 #error "uh oh" 34 #endif 35 36 #if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF. 37 #error "uh oh" 38 #endif 39 40 // Now test that signed arithmetic that pushes us over a limit is properly 41 // diagnosed. 42 #if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}} 43 #endif 44 45 #if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}} 46 #endif 47 48