From ff426a6250e9fa3860c00ef7c5c7e53534a4dc67 Mon Sep 17 00:00:00 2001 From: Karl-Johan Karlsson Date: Fri, 24 Mar 2023 10:33:46 +0100 Subject: [PATCH] [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 --- compiler-rt/lib/builtins/int_mulo_impl.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/builtins/int_mulo_impl.inc b/compiler-rt/lib/builtins/int_mulo_impl.inc index 592b789..27e7c8c 100644 --- a/compiler-rt/lib/builtins/int_mulo_impl.inc +++ b/compiler-rt/lib/builtins/int_mulo_impl.inc @@ -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; -- 2.7.4