Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c04d35f

Browse files
committed
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
1 parent c757a3d commit c04d35f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

config/c-compiler.m4

+8-4
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,17 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P
310310
# and define HAVE__BUILTIN_OP_OVERFLOW if so.
311311
#
312312
# Check for the most complicated case, 64 bit multiplication, as a
313-
# proxy for all of the operations. Have to link to be sure to
314-
# recognize a missing __builtin_mul_overflow.
313+
# proxy for all of the operations. Use volatile variables to avoid the
314+
# compiler computing result at compile time, even though the runtime
315+
# might not supply operation. Have to link to be sure to recognize a
316+
# missing __builtin_mul_overflow.
315317
AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW],
316318
[AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow,
317319
[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
318-
[PG_INT64_TYPE result;
319-
__builtin_mul_overflow((PG_INT64_TYPE) 1, (PG_INT64_TYPE) 2, &result);]
320+
[PG_INT64_TYPE a = 1;
321+
PG_INT64_TYPE b = 1;
322+
PG_INT64_TYPE result;
323+
__builtin_mul_overflow(*(volatile PG_INT64_TYPE *) a, *(volatile PG_INT64_TYPE *) b, &result);]
320324
)],
321325
[pgac_cv__builtin_op_overflow=yes],
322326
[pgac_cv__builtin_op_overflow=no])])

configure

+3-1
Original file line numberDiff line numberDiff line change
@@ -14488,8 +14488,10 @@ else
1448814488
int
1448914489
main ()
1449014490
{
14491+
PG_INT64_TYPE a = 1;
14492+
PG_INT64_TYPE b = 1;
1449114493
PG_INT64_TYPE result;
14492-
__builtin_mul_overflow((PG_INT64_TYPE) 1, (PG_INT64_TYPE) 2, &result);
14494+
__builtin_mul_overflow(*(volatile PG_INT64_TYPE *) a, *(volatile PG_INT64_TYPE *) b, &result);
1449314495
1449414496
;
1449514497
return 0;

0 commit comments

Comments
 (0)