fix last change of mul overflow builtin breaking non-windows compilations

Tue, 07 Feb 2023 21:37:55 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 07 Feb 2023 21:37:55 +0100
changeset 651
19d1a8422f6e
parent 650
77021e06b1a8
child 652
bf817b825ed2

fix last change of mul overflow builtin breaking non-windows compilations

now we use the generic builtin and leave the type resolution to the compiler

src/cx/common.h file | annotate | diff | comparison | revisions
src/cx/utils.h file | annotate | diff | comparison | revisions
test/selftest.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/cx/common.h	Tue Feb 07 20:08:45 2023 +0100
     1.2 +++ b/src/cx/common.h	Tue Feb 07 21:37:55 2023 +0100
     1.3 @@ -105,16 +105,11 @@
     1.4  );
     1.5  
     1.6  #ifdef _WIN32
     1.7 +
     1.8  #ifdef __MINGW32__
     1.9  #include <sys/types.h>
    1.10  #endif // __MINGW32__
    1.11 -#ifndef __WORDSIZE
    1.12 -#ifdef _WIN64
    1.13 -#define __WORDSIZE 64
    1.14 -#else
    1.15 -#define __WORDSIZE 32
    1.16 -#endif // _WIN64
    1.17 -#endif // __WORDSIZE
    1.18 +
    1.19  #else // !_WIN32
    1.20  
    1.21  #include <sys/types.h>
     2.1 --- a/src/cx/utils.h	Tue Feb 07 20:08:45 2023 +0100
     2.2 +++ b/src/cx/utils.h	Tue Feb 07 21:37:55 2023 +0100
     2.3 @@ -56,9 +56,8 @@
     2.4  #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN)
     2.5  #define CX_SZMUL_BUILTIN
     2.6  
     2.7 -#if __WORDSIZE == 32
     2.8  /**
     2.9 - * Alias for \c __builtin_umull_overflow.
    2.10 + * Alias for \c __builtin_mul_overflow.
    2.11   *
    2.12   * Performs a multiplication of size_t values and checks for overflow.
    2.13   *
    2.14 @@ -69,22 +68,7 @@
    2.15   * @return zero, if no overflow occurred and the result is correct, non-zero
    2.16   * otherwise
    2.17   */
    2.18 -#define cx_szmul(a, b, result) __builtin_umull_overflow(a, b, result)
    2.19 -#else // __WORDSIZE != 32
    2.20 -/**
    2.21 - * Alias for \c __builtin_umulll_overflow.
    2.22 - *
    2.23 - * Performs a multiplication of size_t values and checks for overflow.
    2.24 - *
    2.25 - * @param a first operand
    2.26 - * @param b second operand
    2.27 - * @param result a pointer to a size_t, where the result should
    2.28 - * be stored
    2.29 - * @return zero, if no overflow occurred and the result is correct, non-zero
    2.30 - * otherwise
    2.31 - */
    2.32 -#define cx_szmul(a, b, result) __builtin_umulll_overflow(a, b, result)
    2.33 -#endif // __WORDSIZE
    2.34 +#define cx_szmul(a, b, result) __builtin_mul_overflow(a, b, result)
    2.35  
    2.36  #else // no GNUC or clang bultin
    2.37  
     3.1 --- a/test/selftest.cpp	Tue Feb 07 20:08:45 2023 +0100
     3.2 +++ b/test/selftest.cpp	Tue Feb 07 21:37:55 2023 +0100
     3.3 @@ -37,7 +37,3 @@
     3.4      EXPECT_GE(UCX_VERSION_MAJOR, 3);
     3.5      EXPECT_GE(UCX_VERSION, 3 << 16);
     3.6  }
     3.7 -
     3.8 -TEST(SelfTest, CommonDefinitions) {
     3.9 -    EXPECT_EQ(__WORDSIZE, 8 * sizeof(void*));
    3.10 -}

mercurial