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

Karl-Johan Karlsson via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 03:11:16 PDT 2023


Author: Karl-Johan Karlsson
Date: 2023-03-24T11:02:34+01:00
New Revision: ff426a6250e9fa3860c00ef7c5c7e53534a4dc67

URL: https://github.com/llvm/llvm-project/commit/ff426a6250e9fa3860c00ef7c5c7e53534a4dc67
DIFF: https://github.com/llvm/llvm-project/commit/ff426a6250e9fa3860c00ef7c5c7e53534a4dc67.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/builtins/int_mulo_impl.inc

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/int_mulo_impl.inc b/compiler-rt/lib/builtins/int_mulo_impl.inc
index 592b7893edbdc..27e7c8c43d600 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;


        


More information about the llvm-commits mailing list