1*a68d90faSPeter Collingbourne // RUN: %clangxx -DSUB_I32 -fsanitize=unsigned-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I32 2*a68d90faSPeter Collingbourne // RUN: %clangxx -DSUB_I64 -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I64 3*a68d90faSPeter Collingbourne // RUN: %clangxx -DSUB_I128 -fsanitize=unsigned-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-SUB_I128 4ba869e79SAlexey Samsonov 5ba869e79SAlexey Samsonov #include <stdint.h> 6ba869e79SAlexey Samsonov #include <stdio.h> 7ba869e79SAlexey Samsonov main()8ba869e79SAlexey Samsonovint main() { 9ba869e79SAlexey Samsonov // These promote to 'int'. 10ba869e79SAlexey Samsonov (void)(uint8_t(0) - uint8_t(0x7f)); 11ba869e79SAlexey Samsonov (void)(uint16_t(0) - uint16_t(0x7fff)); 12ba869e79SAlexey Samsonov 13ba869e79SAlexey Samsonov #ifdef SUB_I32 14ba869e79SAlexey Samsonov (void)(uint32_t(1) - uint32_t(2)); 15ba869e79SAlexey Samsonov // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int' 16ba869e79SAlexey Samsonov #endif 17ba869e79SAlexey Samsonov 18ba869e79SAlexey Samsonov #ifdef SUB_I64 19ba869e79SAlexey Samsonov (void)(uint64_t(8000000000000000000ll) - uint64_t(9000000000000000000ll)); 20ba869e79SAlexey Samsonov // CHECK-SUB_I64: 8000000000000000000 - 9000000000000000000 cannot be represented in type 'unsigned {{long( long)?}}' 21ba869e79SAlexey Samsonov #endif 22ba869e79SAlexey Samsonov 23ba869e79SAlexey Samsonov #ifdef SUB_I128 24*a68d90faSPeter Collingbourne # if defined(__SIZEOF_INT128__) && !defined(_WIN32) 25ba869e79SAlexey Samsonov (void)((__uint128_t(1) << 126) - (__uint128_t(1) << 127)); 26ba869e79SAlexey Samsonov # else 27ba869e79SAlexey Samsonov puts("__int128 not supported\n"); 28ba869e79SAlexey Samsonov # endif 29ba869e79SAlexey Samsonov // CHECK-SUB_I128: {{0x40000000000000000000000000000000 - 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128'|__int128 not supported}} 30ba869e79SAlexey Samsonov #endif 31ba869e79SAlexey Samsonov } 32