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
This commit is contained in:
Richard Smith 2012-11-29 23:03:58 +00:00
parent 2b14712eca
commit 57000c38fc
6 changed files with 45 additions and 11 deletions

View File

@ -14,6 +14,7 @@
// This test assumes float and double are IEEE-754 single- and double-precision.
#include <stdint.h>
#include <stdio.h>
#include <string.h>
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

View File

@ -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 <stdint.h>
#include <stdio.h>
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
}

View File

@ -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;
}

View File

@ -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 <stdint.h>
#include <stdio.h>
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
}

View File

@ -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 <stdint.h>
#include <stdio.h>
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
}

View File

@ -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 <stdint.h>
#include <stdio.h>
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
}