llvm-project/compiler-rt/lib/builtins/mulvsi3.c
Karl-Johan Karlsson 3032189c0b [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
2023-03-09 08:37:47 +01:00

22 lines
738 B
C

//===-- mulvsi3.c - Implement __mulvsi3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __mulvsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
#define fixint_t si_int
#define fixuint_t su_int
#include "int_mulv_impl.inc"
// Returns: a * b
// Effects: aborts if a * b overflows
COMPILER_RT_ABI si_int __mulvsi3(si_int a, si_int b) { return __mulvXi3(a, b); }