Fix UBSan report in "round"

This commit is contained in:
Alexey Milovidov 2021-01-29 04:03:38 +03:00
parent 9c111a7bdb
commit eb0473c3f9
4 changed files with 11 additions and 1 deletions

View File

@ -84,10 +84,12 @@
# define NO_SANITIZE_UNDEFINED __attribute__((__no_sanitize__("undefined"))) # define NO_SANITIZE_UNDEFINED __attribute__((__no_sanitize__("undefined")))
# define NO_SANITIZE_ADDRESS __attribute__((__no_sanitize__("address"))) # define NO_SANITIZE_ADDRESS __attribute__((__no_sanitize__("address")))
# define NO_SANITIZE_THREAD __attribute__((__no_sanitize__("thread"))) # define NO_SANITIZE_THREAD __attribute__((__no_sanitize__("thread")))
# define ALWAYS_INLINE_NO_SANITIZE_UNDEFINED __attribute__((__always_inline__, __no_sanitize__("undefined")))
#else /// It does not work in GCC. GCC 7 cannot recognize this attribute and GCC 8 simply ignores it. #else /// It does not work in GCC. GCC 7 cannot recognize this attribute and GCC 8 simply ignores it.
# define NO_SANITIZE_UNDEFINED # define NO_SANITIZE_UNDEFINED
# define NO_SANITIZE_ADDRESS # define NO_SANITIZE_ADDRESS
# define NO_SANITIZE_THREAD # define NO_SANITIZE_THREAD
# define ALWAYS_INLINE_NO_SANITIZE_UNDEFINED ALWAYS_INLINE
#endif #endif
/// A template function for suppressing warnings about unused variables or function results. /// A template function for suppressing warnings about unused variables or function results.

View File

@ -101,7 +101,8 @@ struct IntegerRoundingComputation
return scale; return scale;
} }
static ALWAYS_INLINE T computeImpl(T x, T scale) /// Integer overflow is Ok.
static ALWAYS_INLINE_NO_SANITIZE_UNDEFINED T computeImpl(T x, T scale)
{ {
switch (rounding_mode) switch (rounding_mode)
{ {

View File

@ -0,0 +1 @@
9223372036854775700

View File

@ -0,0 +1,6 @@
-- Overflow during integer rounding is implementation specific behaviour.
-- This test allows to be aware if the impkementation changes.
-- Changing the implementation specific behaviour is Ok.
-- and should not be treat as incompatibility (simply update test result then).
SELECT round(-9223372036854775808, -2);