[compiler-rt] Fix signed integer overflow in int_mulo_impl.inc

When compiling compiler-rt with -fsanitize=undefined and running testcases you
end up with the following warning:

UBSan:/repo/uabkaka/llvm-project/compiler-rt/lib/builtins/int_mulo_impl.inc:24:23: signed integer overflow: -1 * -2147483648 cannot be represented in type 'si_int' (aka 'long')

This can be avoided by doing the multiplication in a matching unsigned variant
of the type.

This was found in an out of tree target.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D146623
This commit is contained in:
Karl-Johan Karlsson
2023-03-24 10:33:46 +01:00
parent 2a6e39dbf8
commit ff426a6250

View File

@@ -21,7 +21,7 @@ static __inline fixint_t __muloXi4(fixint_t a, fixint_t b, int *overflow) {
const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1));
const fixint_t MAX = ~MIN;
*overflow = 0;
fixint_t result = a * b;
fixint_t result = (fixuint_t)a * b;
if (a == MIN) {
if (b != 0 && b != 1)
*overflow = 1;