mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user