From 57000c38fc80c9d292e729186342253f32ee88da Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Nov 2012 23:03:58 +0000 Subject: [PATCH] ubsan: Disable __int128 tests if the host Clang does not support it. These tests will still fail if compiler-rt was built with a compiler without __int128 support, but the host compiler has __int128 support. llvm-svn: 168955 --- compiler-rt/lib/ubsan/lit_tests/Float/cast-overflow.cpp | 10 +++++++++- compiler-rt/lib/ubsan/lit_tests/Integer/add-overflow.cpp | 9 +++++++-- compiler-rt/lib/ubsan/lit_tests/Integer/div-zero.cpp | 10 ++++++++-- compiler-rt/lib/ubsan/lit_tests/Integer/sub-overflow.cpp | 9 +++++++-- compiler-rt/lib/ubsan/lit_tests/Integer/uadd-overflow.cpp | 9 +++++++-- compiler-rt/lib/ubsan/lit_tests/Integer/usub-overflow.cpp | 9 +++++++-- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/compiler-rt/lib/ubsan/lit_tests/Float/cast-overflow.cpp b/compiler-rt/lib/ubsan/lit_tests/Float/cast-overflow.cpp index b9c5d38..24b654a 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Float/cast-overflow.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Float/cast-overflow.cpp @@ -14,6 +14,7 @@ // This test assumes float and double are IEEE-754 single- and double-precision. #include +#include #include float Inf; @@ -30,8 +31,10 @@ int main(int argc, char **argv) { float MaxFloatRepresentableAsUInt = 0xffffff00u; (unsigned int)MaxFloatRepresentableAsUInt; // ok +#ifdef __SIZEOF_INT128__ unsigned __int128 FloatMaxAsUInt128 = -((unsigned __int128)1 << 104); (void)(float)FloatMaxAsUInt128; // ok +#endif // Build a '+Inf'. char InfVal[] = { 0x00, 0x00, 0x80, 0x7f }; @@ -71,8 +74,13 @@ int main(int argc, char **argv) { // Integer -> floating point overflow. case '6': - // CHECK-6: fatal error: value 0xffffff00000000000000000000000001 is outside the range of representable values of type 'float' + // CHECK-6: {{fatal error: value 0xffffff00000000000000000000000001 is outside the range of representable values of type 'float'|__int128 not supported}} +#ifdef __SIZEOF_INT128__ return (float)(FloatMaxAsUInt128 + 1); +#else + puts("__int128 not supported"); + return 0; +#endif // FIXME: The backend cannot lower __fp16 operations on x86 yet. //case '7': // (__fp16)65504; // ok diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/add-overflow.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/add-overflow.cpp index 020ae76..179099a 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Integer/add-overflow.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/add-overflow.cpp @@ -3,6 +3,7 @@ // RUN: %clang -DADD_I128 -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=ADD_I128 #include +#include int main() { // These promote to 'int'. @@ -12,7 +13,7 @@ int main() { #ifdef ADD_I32 int32_t k = 0x12345678; k += 0x789abcde; - // CHECK-ADD_I32: add-overflow.cpp:14:5: fatal error: signed integer overflow: 305419896 + 2023406814 cannot be represented in type 'int32_t' (aka 'int') + // CHECK-ADD_I32: add-overflow.cpp:[[@LINE-1]]:5: fatal error: signed integer overflow: 305419896 + 2023406814 cannot be represented in type 'int32_t' (aka 'int') #endif #ifdef ADD_I64 @@ -21,7 +22,11 @@ int main() { #endif #ifdef ADD_I128 +# ifdef __SIZEOF_INT128__ (void)((__int128_t(1) << 126) + (__int128_t(1) << 126)); - // CHECK-ADD_I128: 0x40000000000000000000000000000000 + 0x40000000000000000000000000000000 cannot be represented in type '__int128' +# else + puts("__int128 not supported"); +# endif + // CHECK-ADD_I128: {{0x40000000000000000000000000000000 \+ 0x40000000000000000000000000000000 cannot be represented in type '__int128'|__int128 not supported}} #endif } diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/div-zero.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/div-zero.cpp index f024835..b9aed51 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Integer/div-zero.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/div-zero.cpp @@ -1,9 +1,15 @@ // RUN: %clang -fsanitize=integer-divide-by-zero -DDIVIDEND=0 %s -o %t && %t 2>&1 | FileCheck %s // RUN: %clang -fsanitize=integer-divide-by-zero -DDIVIDEND=1U %s -o %t && %t 2>&1 | FileCheck %s // RUN: %clang -fsanitize=float-divide-by-zero -DDIVIDEND=1.5 %s -o %t && %t 2>&1 | FileCheck %s -// RUN: %clang -fsanitize=integer-divide-by-zero -DDIVIDEND='__int128(123)' %s -o %t && %t 2>&1 | FileCheck %s +// RUN: %clang -fsanitize=integer-divide-by-zero -DDIVIDEND='intmax(123)' %s -o %t && %t 2>&1 | FileCheck %s + +#ifdef __SIZEOF_INT128__ +typedef __int128 intmax; +#else +typedef long long intmax; +#endif int main() { - // CHECK: div-zero.cpp:8:12: fatal error: division by zero + // CHECK: div-zero.cpp:[[@LINE+1]]:12: fatal error: division by zero DIVIDEND / 0; } diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/sub-overflow.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/sub-overflow.cpp index ee43154..e432cb8 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Integer/sub-overflow.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/sub-overflow.cpp @@ -3,6 +3,7 @@ // RUN: %clang -DSUB_I128 -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=SUB_I128 #include +#include int main() { // These promote to 'int'. @@ -11,7 +12,7 @@ int main() { #ifdef SUB_I32 (void)(int32_t(-2) - int32_t(0x7fffffff)); - // CHECK-SUB_I32: sub-overflow.cpp:13:22: fatal error: signed integer overflow: -2 - 2147483647 cannot be represented in type 'int' + // CHECK-SUB_I32: sub-overflow.cpp:[[@LINE-1]]:22: fatal error: signed integer overflow: -2 - 2147483647 cannot be represented in type 'int' #endif #ifdef SUB_I64 @@ -20,7 +21,11 @@ int main() { #endif #ifdef SUB_I128 +# ifdef __SIZEOF_INT128__ (void)(-(__int128_t(1) << 126) - (__int128_t(1) << 126) - 1); - // CHECK-SUB_I128: 0x80000000000000000000000000000000 - 1 cannot be represented in type '__int128' +# else + puts("__int128 not supported"); +# endif + // CHECK-SUB_I128: {{0x80000000000000000000000000000000 - 1 cannot be represented in type '__int128'|__int128 not supported}} #endif } diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/uadd-overflow.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/uadd-overflow.cpp index bd25bd7..e373596 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Integer/uadd-overflow.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/uadd-overflow.cpp @@ -3,6 +3,7 @@ // RUN: %clang -DADD_I128 -fsanitize=unsigned-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=ADD_I128 #include +#include int main() { // These promote to 'int'. @@ -12,7 +13,7 @@ int main() { #ifdef ADD_I32 uint32_t k = 0x87654321; k += 0xedcba987; - // CHECK-ADD_I32: uadd-overflow.cpp:14:5: fatal error: unsigned integer overflow: 2271560481 + 3989547399 cannot be represented in type 'uint32_t' (aka 'unsigned int') + // CHECK-ADD_I32: uadd-overflow.cpp:[[@LINE-1]]:5: fatal error: unsigned integer overflow: 2271560481 + 3989547399 cannot be represented in type 'uint32_t' (aka 'unsigned int') #endif #ifdef ADD_I64 @@ -21,7 +22,11 @@ int main() { #endif #ifdef ADD_I128 +# ifdef __SIZEOF_INT128__ (void)((__uint128_t(1) << 127) + (__uint128_t(1) << 127)); - // CHECK-ADD_I128: 0x80000000000000000000000000000000 + 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128' +# else + puts("__int128 not supported"); +# endif + // CHECK-ADD_I128: {{0x80000000000000000000000000000000 \+ 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128'|__int128 not supported}} #endif } diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/usub-overflow.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/usub-overflow.cpp index e91810b..c8d9bab 100644 --- a/compiler-rt/lib/ubsan/lit_tests/Integer/usub-overflow.cpp +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/usub-overflow.cpp @@ -3,6 +3,7 @@ // RUN: %clang -DSUB_I128 -fsanitize=unsigned-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=SUB_I128 #include +#include int main() { // These promote to 'int'. @@ -11,7 +12,7 @@ int main() { #ifdef SUB_I32 (void)(uint32_t(1) - uint32_t(2)); - // CHECK-SUB_I32: usub-overflow.cpp:13:22: fatal error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int' + // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: fatal error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int' #endif #ifdef SUB_I64 @@ -20,7 +21,11 @@ int main() { #endif #ifdef SUB_I128 +# ifdef __SIZEOF_INT128__ (void)((__uint128_t(1) << 126) - (__uint128_t(1) << 127)); - // CHECK-SUB_I128: 0x40000000000000000000000000000000 - 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128' +# else + puts("__int128 not supported\n"); +# endif + // CHECK-SUB_I128: {{0x40000000000000000000000000000000 - 0x80000000000000000000000000000000 cannot be represented in type 'unsigned __int128'|__int128 not supported}} #endif } -- 2.7.4