mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[compiler-rt] Avoid signed shift overflow in __muloXi4 and __mulvXi3
When compiling compiler-rt with -fsanitize=undefined and running testcases you end up with the following warning: UBSan: int_mulo_impl.inc:21:36: left shift of 1 by 63 places cannot be represented in type 'di_int' (aka 'long long') This can be avoided by simply doing the shift in a matching unsigned variant of the type. The same kind of pattern seems to exist in int_mulv_impl.inc This was found in an out of tree target. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D145556
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
static __inline fixint_t __muloXi4(fixint_t a, fixint_t b, int *overflow) {
|
||||
const int N = (int)(sizeof(fixint_t) * CHAR_BIT);
|
||||
const fixint_t MIN = (fixint_t)1 << (N - 1);
|
||||
const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1));
|
||||
const fixint_t MAX = ~MIN;
|
||||
*overflow = 0;
|
||||
fixint_t result = a * b;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
static __inline fixint_t __mulvXi3(fixint_t a, fixint_t b) {
|
||||
const int N = (int)(sizeof(fixint_t) * CHAR_BIT);
|
||||
const fixint_t MIN = (fixint_t)1 << (N - 1);
|
||||
const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1));
|
||||
const fixint_t MAX = ~MIN;
|
||||
if (a == MIN) {
|
||||
if (b == 0 || b == 1)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define fixint_t di_int
|
||||
#define fixuint_t du_int
|
||||
#include "int_mulo_impl.inc"
|
||||
|
||||
// Returns: a * b
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define fixint_t si_int
|
||||
#define fixuint_t su_int
|
||||
#include "int_mulo_impl.inc"
|
||||
|
||||
// Returns: a * b
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// Effects: sets *overflow to 1 if a * b overflows
|
||||
|
||||
#define fixint_t ti_int
|
||||
#define fixuint_t tu_int
|
||||
#include "int_mulo_impl.inc"
|
||||
|
||||
COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define fixint_t di_int
|
||||
#define fixuint_t du_int
|
||||
#include "int_mulv_impl.inc"
|
||||
|
||||
// Returns: a * b
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define fixint_t si_int
|
||||
#define fixuint_t su_int
|
||||
#include "int_mulv_impl.inc"
|
||||
|
||||
// Returns: a * b
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// Effects: aborts if a * b overflows
|
||||
|
||||
#define fixint_t ti_int
|
||||
#define fixuint_t tu_int
|
||||
#include "int_mulv_impl.inc"
|
||||
|
||||
COMPILER_RT_ABI ti_int __mulvti3(ti_int a, ti_int b) { return __mulvXi3(a, b); }
|
||||
|
||||
Reference in New Issue
Block a user