Allowed some UB under UBSan #3926

This commit is contained in:
Alexey Milovidov 2018-12-27 02:55:09 +03:00
parent 2b58438737
commit 732f60c8be
13 changed files with 13 additions and 15 deletions

View File

@ -109,8 +109,8 @@
/// It is useful in case when compiler cannot see (and exploit) it, but UBSan can.
/// Example: multiplication of signed integers with possibility of overflow when both sides are from user input.
#if defined(__clang__)
#define NO_UNDEFINED_SANITIZER __attribute__((__no_sanitize__("undefined")))
#define NO_SANITIZE_UNDEFINED __attribute__((__no_sanitize__("undefined")))
#else
/// It does not work in GCC. GCC 7 cannot recognize this attribute and GCC 8 simply ignores it.
#define NO_UNDEFINED_SANITIZER
#define NO_SANITIZE_UNDEFINED
#endif

View File

@ -1,7 +1,5 @@
#pragma once
#include <Columns/ColumnArray.h>
#include <Functions/FunctionUnaryArithmetic.h>
#include <Functions/FunctionHelpers.h>
#include <IO/WriteHelpers.h>
#include <DataTypes/getLeastSupertype.h>

View File

@ -11,7 +11,7 @@ struct AbsImpl
{
using ResultType = std::conditional_t<IsDecimalNumber<A>, A, typename NumberTraits::ResultOfAbs<A>::Type>;
static inline ResultType apply(A a)
static inline NO_SANITIZE_UNDEFINED ResultType apply(A a)
{
if constexpr (IsDecimalNumber<A>)
return a < 0 ? A(-a) : a;

View File

@ -10,7 +10,7 @@ struct BitRotateLeftImpl
using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return (static_cast<Result>(a) << static_cast<Result>(b))
| (static_cast<Result>(a) >> ((sizeof(Result) * 8) - static_cast<Result>(b)));

View File

@ -10,7 +10,7 @@ struct BitRotateRightImpl
using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return (static_cast<Result>(a) >> static_cast<Result>(b))
| (static_cast<Result>(a) << ((sizeof(Result) * 8) - static_cast<Result>(b)));

View File

@ -10,7 +10,7 @@ struct BitShiftLeftImpl
using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return static_cast<Result>(a) << static_cast<Result>(b);
}

View File

@ -10,7 +10,7 @@ struct BitShiftRightImpl
using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return static_cast<Result>(a) >> static_cast<Result>(b);
}

View File

@ -11,7 +11,7 @@ struct DivideFloatingImpl
static const constexpr bool allow_decimal = true;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return static_cast<Result>(a) / b;
}

View File

@ -12,7 +12,7 @@ struct MinusImpl
static const constexpr bool allow_decimal = true;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return static_cast<Result>(a) - b;
}

View File

@ -12,7 +12,7 @@ struct MultiplyImpl
static const constexpr bool allow_decimal = true;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
return static_cast<Result>(a) * b;
}

View File

@ -10,7 +10,7 @@ struct NegateImpl
{
using ResultType = std::conditional_t<IsDecimalNumber<A>, A, typename NumberTraits::ResultOfNegate<A>::Type>;
static inline ResultType apply(A a)
static inline NO_SANITIZE_UNDEFINED ResultType apply(A a)
{
return -static_cast<ResultType>(a);
}

View File

@ -12,7 +12,7 @@ struct PlusImpl
static const constexpr bool allow_decimal = true;
template <typename Result = ResultType>
static inline Result apply(A a, B b)
static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b)
{
/// Next everywhere, static_cast - so that there is no wrong result in expressions of the form Int64 c = UInt32(a) * Int32(-1).
return static_cast<Result>(a) + b;

View File

@ -6,7 +6,7 @@
/// On overlow, the function returns unspecified value.
inline uint64_t intExp2(int x)
inline NO_SANITIZE_UNDEFINED uint64_t intExp2(int x)
{
return 1ULL << x;
}