From: Andres Freund Date: Sat, 16 Dec 2017 20:49:41 +0000 (-0800) Subject: Try to detect runtime unavailability of __builtin_mul_overflow(int64). X-Git-Tag: REL_11_BETA1~1062 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c04d35f442a8c4fd5a20103b31839ec52fce3046;p=postgresql Try to detect runtime unavailability of __builtin_mul_overflow(int64). On some systems the results of 64 bit __builtin_mul_overflow() operations can be computed at compile time, but not at runtime. The known cases are arm buildfar animals using clang where the runtime operation is implemented in a unavailable function. Try to avoid compile-time computation by using volatile arguments to __builtin_mul_overflow(). In that case we hopefully will get a link error when unavailable, similar to what buildfarm animals dangomushi and gull are reporting. Author: Andres Freund Discussion: https://postgr.es/m/20171213213754.pydkyjs6bt2hvsdb@alap3.anarazel.de --- diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index 67323ade12..b35436481c 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -310,13 +310,17 @@ 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. Have to link to be sure to -# recognize a missing __builtin_mul_overflow. +# 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. 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 result; -__builtin_mul_overflow((PG_INT64_TYPE) 1, (PG_INT64_TYPE) 2, &result);] +[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);] )], [pgac_cv__builtin_op_overflow=yes], [pgac_cv__builtin_op_overflow=no])]) diff --git a/configure b/configure index 58eafd31c5..22ca4230fc 100755 --- a/configure +++ b/configure @@ -14488,8 +14488,10 @@ else int main () { +PG_INT64_TYPE a = 1; +PG_INT64_TYPE b = 1; PG_INT64_TYPE result; -__builtin_mul_overflow((PG_INT64_TYPE) 1, (PG_INT64_TYPE) 2, &result); +__builtin_mul_overflow(*(volatile PG_INT64_TYPE *) a, *(volatile PG_INT64_TYPE *) b, &result); ; return 0;