summaryrefslogtreecommitdiff
path: root/config/c-compiler.m4
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-11-14 15:03:55 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-11-14 15:03:55 -0500
commit7518049980be1d90264addab003476ae105f70d4 (patch)
tree78f553ca09439d572a6c897dee4dd3bae7b4eea3 /config/c-compiler.m4
parent91aec93e6089a5ba49cce0aca3bf7f7022d62ea4 (diff)
downloadpostgresql-7518049980be1d90264addab003476ae105f70d4.tar.gz
Prevent int128 from requiring more than MAXALIGN alignment.
Our initial work with int128 neglected alignment considerations, an oversight that came back to bite us in bug #14897 from Vincent Lachenal. It is unsurprising that int128 might have a 16-byte alignment requirement; what's slightly more surprising is that even notoriously lax Intel chips sometimes enforce that. Raising MAXALIGN seems out of the question: the costs in wasted disk and memory space would be significant, and there would also be an on-disk compatibility break. Nor does it seem very practical to try to allow some data structures to have more-than-MAXALIGN alignment requirement, as we'd have to push knowledge of that throughout various code that copies data structures around. The only way out of the box is to make type int128 conform to the system's alignment assumptions. Fortunately, gcc supports that via its __attribute__(aligned()) pragma; and since we don't currently support int128 on non-gcc-workalike compilers, we shouldn't be losing any platform support this way. Although we could have just done pg_attribute_aligned(MAXIMUM_ALIGNOF) and called it a day, I did a little bit of extra work to make the code more portable than that: it will also support int128 on compilers without __attribute__(aligned()), if the native alignment of their 128-bit-int type is no more than that of int64. Add a regression test case that exercises the one known instance of the problem, in parallel aggregation over a bigint column. This will need to be back-patched, along with the preparatory commit 91aec93e6. But let's see what the buildfarm makes of it first. Discussion: https://postgr.es/m/20171110185747.31519.28038@wrigleys.postgresql.org
Diffstat (limited to 'config/c-compiler.m4')
-rw-r--r--config/c-compiler.m49
1 files changed, 6 insertions, 3 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 6dcc790649..492f6832cf 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -96,9 +96,11 @@ undefine([Ac_cachevar])dnl
# PGAC_TYPE_128BIT_INT
# ---------------------
# Check if __int128 is a working 128 bit integer type, and if so
-# define PG_INT128_TYPE to that typename. This currently only detects
-# a GCC/clang extension, but support for different environments may be
-# added in the future.
+# define PG_INT128_TYPE to that typename, and define ALIGNOF_PG_INT128_TYPE
+# as its alignment requirement.
+#
+# This currently only detects a GCC/clang extension, but support for other
+# environments may be added in the future.
#
# For the moment we only test for support for 128bit math; support for
# 128bit literals and snprintf is not required.
@@ -128,6 +130,7 @@ return 1;
[pgac_cv__128bit_int=no])])
if test x"$pgac_cv__128bit_int" = xyes ; then
AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
+ AC_CHECK_ALIGNOF(PG_INT128_TYPE)
fi])# PGAC_TYPE_128BIT_INT