diff --git a/lib/ubsan/ubsan_value.cc b/lib/ubsan/ubsan_value.cc index 8e298d40a9..79dc4c8e82 100644 --- a/lib/ubsan/ubsan_value.cc +++ b/lib/ubsan/ubsan_value.cc @@ -83,11 +83,11 @@ FloatMax Value::getFloatValue() const { #endif case 32: { float Value; -#if defined(__BIG_ENDIAN__) && !defined(__mips__) - // For big endian the float value is in the highest addressed 4 bytes - // (the least significant bits) but we must also consider that we might - // have a 32-bit type. - internal_memcpy(&Value, ((const char*)&Val + 1) - 4, 4); +#if defined(__BIG_ENDIAN__) + // For big endian the float value is in the last 4 bytes. + // On some targets we may only have 4 bytes so we count backwards from + // the end of Val to account for both the 32-bit and 64-bit cases. + internal_memcpy(&Value, ((const char*)(&Val + 1)) - 4, 4); #else internal_memcpy(&Value, &Val, 4); #endif