Skip to content

Commit

Permalink
Fixed CORE-6504: Provide same results for date arithmetics when date …
Browse files Browse the repository at this point in the history
…is changed by values near +/-max(bigint)
  • Loading branch information
AlexPeshkoff committed Apr 22, 2021
1 parent 4aa619f commit 7d2b34e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions configure.ac
Expand Up @@ -1095,6 +1095,25 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[main () {
AC_MSG_RESULT($ac_cv_c_double_align)
AC_DEFINE_UNQUOTED(FB_DOUBLE_ALIGN, $ac_cv_c_double_align, [Alignment of double])

AC_MSG_CHECKING(correctness of comparing 64-bit integers)
ac_cv_compare_failed=1
ac_cv_compare_result=failed
savedflags="$CFLAGS"
CFLAGS="$CFLAGS -O3"
AC_RUN_IFELSE([AC_LANG_SOURCE([[typedef long long int SINT64;
static int abs64Compare(SINT64 n1, SINT64 n2) {
n1 = n1 > 0 ? -n1 : n1;
n2 = n2 > 0 ? -n2 : n2;
return n1 == n2 ? 0 : n1 < n2 ? 1 : -1;
}
int main() {
exit (abs64Compare(-9223372036854775808, 3652058) == 1 ? 0 : 1);
}]])],[ac_cv_compare_failed=0
ac_cv_compare_result=success])
CFLAGS="$savedflags"
AC_MSG_RESULT($ac_cv_compare_result)
AC_DEFINE_UNQUOTED(FB_INT64_COMPARE_FAILED, $ac_cv_compare_failed, [Error when comparing 64-bit integers])

dnl EKU: Add any platform specific tests below
case "$PLATFORM" in
LINUX)
Expand Down
9 changes: 9 additions & 0 deletions src/common/utils_proto.h
Expand Up @@ -108,6 +108,15 @@ namespace fb_utils
// Return 0 if they are equal, <0 if n1 < n2 and >0 if n1 > n2.
inline int abs64Compare(SINT64 n1, SINT64 n2)
{
#if FB_INT64_COMPARE_FAILED

This comment has been minimized.

Copy link
@dyemanov

dyemanov Apr 24, 2021

Member

Maybe #ifdef ? And Windows build is broken now:
utils_proto.h(117): error C2106: '=': left operand must be l-value

This comment has been minimized.

Copy link
@asfernandes

asfernandes Apr 24, 2021

Member

First build with this commit worked. Is MININT64 #defined in MSVC?

// avoid compiler bug when comparing minimum INT64
const SINT64 MININT64 = 0x8000000000000000;
if (n1 == MININT64)
return n2 == MININT64 ? 0 : 2;
if (n2 == MININT64)
return -2;
#endif

n1 = n1 > 0 ? -n1 : n1;
n2 = n2 > 0 ? -n2 : n2;
return n1 == n2 ? 0 : n1 < n2 ? 1 : -1;
Expand Down

0 comments on commit 7d2b34e

Please sign in to comment.