Index: projects/compiler-rt/cmake/config-ix.cmake =================================================================== --- projects/compiler-rt/cmake/config-ix.cmake +++ projects/compiler-rt/cmake/config-ix.cmake @@ -233,7 +233,8 @@ 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") Index: projects/compiler-rt/lib/ubsan/ubsan_platform.h =================================================================== --- projects/compiler-rt/lib/ubsan/ubsan_platform.h +++ projects/compiler-rt/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 Index: projects/compiler-rt/lib/ubsan/ubsan_value.cc =================================================================== --- projects/compiler-rt/lib/ubsan/ubsan_value.cc +++ projects/compiler-rt/lib/ubsan/ubsan_value.cc @@ -83,7 +83,13 @@ #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: { Index: projects/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp =================================================================== --- projects/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp +++ projects/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp @@ -82,11 +82,13 @@ // 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; + 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 @@ 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); + 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; + 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); + 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