diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index b35436481c..076656c77f 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -310,18 +310,19 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P # and define HAVE__BUILTIN_OP_OVERFLOW if so. # # Check for the most complicated case, 64 bit multiplication, as a -# proxy for all of the operations. Use volatile variables to avoid the -# compiler computing result at compile time, even though the runtime -# might not supply operation. Have to link to be sure to recognize a -# missing __builtin_mul_overflow. +# proxy for all of the operations. To detect the case where the compiler +# knows the function but library support is missing, we must link not just +# compile, and store the results in global variables so the compiler doesn't +# optimize away the call. AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW], [AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([], -[PG_INT64_TYPE a = 1; +[AC_LINK_IFELSE([AC_LANG_PROGRAM([ +PG_INT64_TYPE a = 1; PG_INT64_TYPE b = 1; 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=no])]) if test x"$pgac_cv__builtin_op_overflow" = xyes ; then diff --git a/configure b/configure index 22ca4230fc..d9b7b8d7ec 100755 --- a/configure +++ b/configure @@ -14485,14 +14485,15 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -int -main () -{ PG_INT64_TYPE a = 1; PG_INT64_TYPE b = 1; 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; }