diff options
author | Bill Seurer <seurer@linux.vnet.ibm.com> | 2015-04-01 15:33:22 +0000 |
---|---|---|
committer | Bill Seurer <seurer@linux.vnet.ibm.com> | 2015-04-01 15:33:22 +0000 |
commit | 024b02f5c618b030ee4db03dbaed0653046d8018 (patch) | |
tree | ae3fc43bf8ea2386dcc7aa9edb032f8abe0acc1c | |
parent | c53dd083f8ad7b66c27f04b858589a855aeadfaf (diff) |
[PPC64]This activates UBSan for the power architecture.
One test case is updated to allow for differences between power and other architectures in behavior when returning from main in certain instances
http://reviews.llvm.org/D8743
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@233813 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | cmake/config-ix.cmake | 3 | ||||
-rw-r--r-- | lib/ubsan/ubsan_platform.h | 2 | ||||
-rw-r--r-- | lib/ubsan/ubsan_value.cc | 8 | ||||
-rw-r--r-- | test/ubsan/TestCases/Float/cast-overflow.cpp | 24 |
4 files changed, 26 insertions, 11 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index f52639bdb..24cc4af42 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -233,7 +233,8 @@ filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64 mipsel mips64el aarch64 powerpc64 powerpc64le) filter_available_targets(TSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) -filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips mipsel mips64 mips64el) +filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips + mipsel mips64 mips64el powerpc64 powerpc64le) if(ANDROID) set(OS_NAME "Android") diff --git a/lib/ubsan/ubsan_platform.h b/lib/ubsan/ubsan_platform.h index efb7974d4..83fb42b3b 100644 --- a/lib/ubsan/ubsan_platform.h +++ b/lib/ubsan/ubsan_platform.h @@ -16,7 +16,7 @@ // Other platforms should be easy to add, and probably work as-is. #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \ - defined(__aarch64__) || defined(__mips__)) + defined(__aarch64__) || defined(__mips__) || defined(__powerpc64__)) # define CAN_SANITIZE_UB 1 #else # define CAN_SANITIZE_UB 0 diff --git a/lib/ubsan/ubsan_value.cc b/lib/ubsan/ubsan_value.cc index ea91d63bb..215c1956a 100644 --- a/lib/ubsan/ubsan_value.cc +++ b/lib/ubsan/ubsan_value.cc @@ -83,7 +83,13 @@ FloatMax Value::getFloatValue() const { #endif case 32: { float Value; - internal_memcpy(&Value, &Val, 4); +#if defined(__BIG_ENDIAN__) + // For big endian the float value is in the second 4 bytes + // instead of the first 4 bytes. + internal_memcpy(&Value, ((const char*)&Val)+4, 4); +#else + internal_memcpy(&Value, &Val, 4); +#endif return Value; } case 64: { diff --git a/test/ubsan/TestCases/Float/cast-overflow.cpp b/test/ubsan/TestCases/Float/cast-overflow.cpp index 526817153..5e6db7623 100644 --- a/test/ubsan/TestCases/Float/cast-overflow.cpp +++ b/test/ubsan/TestCases/Float/cast-overflow.cpp @@ -82,11 +82,13 @@ int main(int argc, char **argv) { // FIXME: Produce a source location for these checks and test for it here. // Floating point -> integer overflow. - case '0': + case '0': { // Note that values between 0x7ffffe00 and 0x80000000 may or may not // successfully round-trip, depending on the rounding mode. // CHECK-0: runtime error: value 2.14748{{.*}} is outside the range of representable values of type 'int' - return MaxFloatRepresentableAsInt + 0x80; + static int test_int = MaxFloatRepresentableAsInt + 0x80; + return 0; + } case '1': // CHECK-1: runtime error: value -2.14748{{.*}} is outside the range of representable values of type 'int' return MinFloatRepresentableAsInt - 0x100; @@ -96,26 +98,32 @@ int main(int argc, char **argv) { volatile unsigned u = (unsigned)f; return 0; } - case '3': + case '3': { // CHECK-3: runtime error: value 4.2949{{.*}} is outside the range of representable values of type 'unsigned int' - return (unsigned)(MaxFloatRepresentableAsUInt + 0x100); + static int test_int = (unsigned)(MaxFloatRepresentableAsUInt + 0x100); + return 0; + } - case '4': + case '4': { // CHECK-4: runtime error: value {{.*}} is outside the range of representable values of type 'int' - return Inf; + static int test_int = Inf; + return 0; + } case '5': // CHECK-5: runtime error: value {{.*}} is outside the range of representable values of type 'int' return NaN; // Integer -> floating point overflow. - case '6': + case '6': { // CHECK-6: {{runtime error: value 0xffffff00000000000000000000000001 is outside the range of representable values of type 'float'|__int128 not supported}} #ifdef __SIZEOF_INT128__ - return (float)(FloatMaxAsUInt128 + 1); + static int test_int = (float)(FloatMaxAsUInt128 + 1); + return 0; #else puts("__int128 not supported"); return 0; #endif + } // FIXME: The backend cannot lower __fp16 operations on x86 yet. //case '7': // (__fp16)65504; // ok |