Commit c6d21d56 authored by Tom Lane's avatar Tom Lane

Try harder to detect unavailability of __builtin_mul_overflow(int64).

Commit c04d35f4 didn't quite do the job here, because it still allowed
the compiler to deduce that the function call could be optimized away.
Prevent that by putting the arguments and results in global variables.

Discussion: https://postgr.es/m/20171213213754.pydkyjs6bt2hvsdb@alap3.anarazel.de
parent b31a9d7d
...@@ -310,18 +310,19 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P ...@@ -310,18 +310,19 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P
# and define HAVE__BUILTIN_OP_OVERFLOW if so. # and define HAVE__BUILTIN_OP_OVERFLOW if so.
# #
# Check for the most complicated case, 64 bit multiplication, as a # Check for the most complicated case, 64 bit multiplication, as a
# proxy for all of the operations. Use volatile variables to avoid the # proxy for all of the operations. To detect the case where the compiler
# compiler computing result at compile time, even though the runtime # knows the function but library support is missing, we must link not just
# might not supply operation. Have to link to be sure to recognize a # compile, and store the results in global variables so the compiler doesn't
# missing __builtin_mul_overflow. # optimize away the call.
AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW], AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW],
[AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow, [AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([], [AC_LINK_IFELSE([AC_LANG_PROGRAM([
[PG_INT64_TYPE a = 1; PG_INT64_TYPE a = 1;
PG_INT64_TYPE b = 1; PG_INT64_TYPE b = 1;
PG_INT64_TYPE result; PG_INT64_TYPE result;
__builtin_mul_overflow(*(volatile PG_INT64_TYPE *) a, *(volatile PG_INT64_TYPE *) b, &result);] int oflo;
)], ],
[oflo = __builtin_mul_overflow(a, b, &result);])],
[pgac_cv__builtin_op_overflow=yes], [pgac_cv__builtin_op_overflow=yes],
[pgac_cv__builtin_op_overflow=no])]) [pgac_cv__builtin_op_overflow=no])])
if test x"$pgac_cv__builtin_op_overflow" = xyes ; then if test x"$pgac_cv__builtin_op_overflow" = xyes ; then
......
...@@ -14485,14 +14485,15 @@ else ...@@ -14485,14 +14485,15 @@ else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
int
main ()
{
PG_INT64_TYPE a = 1; PG_INT64_TYPE a = 1;
PG_INT64_TYPE b = 1; PG_INT64_TYPE b = 1;
PG_INT64_TYPE result; PG_INT64_TYPE result;
__builtin_mul_overflow(*(volatile PG_INT64_TYPE *) a, *(volatile PG_INT64_TYPE *) b, &result); int oflo;
int
main ()
{
oflo = __builtin_mul_overflow(a, b, &result);
; ;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment