Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -134,7 +134,7 @@ filter_available_targets(MSAN_SUPPORTED_ARCH x86_64) filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm aarch64) filter_available_targets(TSAN_SUPPORTED_ARCH x86_64) -filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 arm aarch64) +filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 arm aarch64 mips) if(ANDROID) set(OS_NAME "Android") Index: lib/sanitizer_common/sanitizer_stacktrace.cc =================================================================== --- lib/sanitizer_common/sanitizer_stacktrace.cc +++ lib/sanitizer_common/sanitizer_stacktrace.cc @@ -25,7 +25,7 @@ #if defined(__powerpc__) || defined(__powerpc64__) // PCs are always 4 byte aligned. return pc - 4; -#elif defined(__sparc__) +#elif defined(__sparc__) || defined(__mips__) return pc - 8; #else return pc - 1; Index: lib/ubsan/ubsan_handlers.cc =================================================================== --- lib/ubsan/ubsan_handlers.cc +++ lib/ubsan/ubsan_handlers.cc @@ -13,7 +13,7 @@ #include "ubsan_handlers.h" #include "ubsan_diag.h" - +#include "sanitizer_common/sanitizer_stacktrace.h" #include "sanitizer_common/sanitizer_common.h" using namespace __sanitizer; @@ -257,12 +257,12 @@ handleVLABoundNotPositive(Data, Bound, Opts); } -static void handleFloatCastOverflow(FloatCastOverflowData *Data, +static void handleFloatCastOverflow(FloatCastOverflowData *Data, uptr Loc, ValueHandle From, ReportOptions Opts) { // TODO: Add deduplication once a SourceLocation is generated for this check. ScopedReport R(Opts); - Diag(getCallerLocation(), DL_Error, + Diag(getCallerLocation(Loc), DL_Error, "value %0 is outside the range of representable values of type %2") << Value(Data->FromType, From) << Data->FromType << Data->ToType; } @@ -270,13 +270,15 @@ void __ubsan::__ubsan_handle_float_cast_overflow(FloatCastOverflowData *Data, ValueHandle From) { GET_REPORT_OPTIONS(false); - handleFloatCastOverflow(Data, From, Opts); + uptr Loc=GET_CALLER_PC(); + handleFloatCastOverflow(Data, Loc, From, Opts); } void __ubsan::__ubsan_handle_float_cast_overflow_abort(FloatCastOverflowData *Data, ValueHandle From) { GET_REPORT_OPTIONS(true); - handleFloatCastOverflow(Data, From, Opts); + uptr Loc=GET_CALLER_PC(); + handleFloatCastOverflow(Data, Loc, From, Opts); } static void handleLoadInvalidValue(InvalidValueData *Data, ValueHandle Val, Index: test/ubsan/TestCases/Float/cast-overflow.cpp =================================================================== --- test/ubsan/TestCases/Float/cast-overflow.cpp +++ test/ubsan/TestCases/Float/cast-overflow.cpp @@ -17,6 +17,7 @@ #include #include #include +#include float Inf; float NaN; @@ -41,12 +42,20 @@ unsigned Zero = NearlyMinusOne; // ok // Build a '+Inf'. +#if __BYTE_ORDER == __LITTLE_ENDIAN char InfVal[] = { 0x00, 0x00, 0x80, 0x7f }; +#else + char InfVal[] = { 0x7f, 0x80, 0x00, 0x00 }; +#endif float Inf; memcpy(&Inf, InfVal, 4); // Build a 'NaN'. +#if __BYTE_ORDER == __LITTLE_ENDIAN char NaNVal[] = { 0x01, 0x00, 0x80, 0x7f }; +#else + char NaNVal[] = { 0x7f, 0x80, 0x00, 0x10 }; +#endif float NaN; memcpy(&NaN, NaNVal, 4);