diff options
| -rw-r--r-- | compiler-rt/cmake/config-ix.cmake | 3 | ||||
| -rw-r--r-- | compiler-rt/lib/ubsan/ubsan_platform.h | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/ubsan/ubsan_value.cc | 8 | ||||
| -rw-r--r-- | compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp | 24 | 
4 files changed, 26 insertions, 11 deletions
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index f52639bdb55..24cc4af4236 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/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/compiler-rt/lib/ubsan/ubsan_platform.h b/compiler-rt/lib/ubsan/ubsan_platform.h index efb7974d46d..83fb42b3b03 100644 --- a/compiler-rt/lib/ubsan/ubsan_platform.h +++ b/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 diff --git a/compiler-rt/lib/ubsan/ubsan_value.cc b/compiler-rt/lib/ubsan/ubsan_value.cc index ea91d63bbb8..215c1956a5c 100644 --- a/compiler-rt/lib/ubsan/ubsan_value.cc +++ b/compiler-rt/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/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp b/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp index 526817153d0..5e6db7623fc 100644 --- a/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp +++ b/compiler-rt/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  | 

