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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy