postgres.git / summary / log / commit / refs
commit 63275ce84d2f571136b585d7493e1ec351388014
Author: Peter Eisentraut <peter@eisentraut.org>
Date: Mon Mar 16 17:56:30 2026 +0000
First released in: 19.0
Hardcode override of typeof_unqual for clang-for-bitcode
The fundamental problem is that when we call clang to generate
bitcode, we might be using configure results from a different
compiler, which might not be fully compatible with the clang we are
using. In practice, clang supports most things other compilers
support, so this has apparently not been a problem in practice.
But commits 4cfce4e62c8, 0af05b5dbb4, and 59292f7aac7 have been
struggling to make typeof_unqual work in this situation. Clang added
support in version 19, GCC in version 14, so if you are using, say,
GCC 14 and Clang 16, the compilation with the latter will fail. Such
combinations are not very likely in practice, because GCC 14 and Clang
19 were released within a few months of each other, and so Linux
distributions are likely to have suitable combinations. But some
buildfarm members and some Fedora versions are affected, so this tries
to fix it.
The fully correct solution would be to run a separate set of configure
tests for that clang-for-bitcode, but that would be very difficult to
implement, and probably of limited use in practice. So the workaround
here is that we hardcodedly override the configure result under clang
based on the version number. As long as we only have a few of these
cases, this should be manageable.
Also swap the order of the tests of typeof_unqual: Commit 59292f7aac7
tested the underscore variant first, but the reasons for that are now
gone.
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3%40eisentraut.org
config/c-compiler.m4 | 8 ++------
configure | 8 ++------
meson.build | 8 ++------
src/include/c.h | 15 +++++++++++++++
4 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 88333ef301d..629572ee350 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -184,13 +184,9 @@ fi])# PGAC_C_TYPEOF
AC_DEFUN([PGAC_C_TYPEOF_UNQUAL],
[AC_CACHE_CHECK(for typeof_unqual, pgac_cv_c_typeof_unqual,
[pgac_cv_c_typeof_unqual=no
-# Test the underscore variant first so that there is a higher chance
-# that clang used for bitcode also supports it, since we don't test
-# that separately.
-#
# Test with a void pointer, because MSVC doesn't handle that, and we
# need that for copyObject().
-for pgac_kw in __typeof_unqual__ typeof_unqual; do
+for pgac_kw in typeof_unqual __typeof_unqual__; do
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[int x = 0;
$pgac_kw(x) y;
@@ -248,7 +244,7 @@ AC_DEFUN([PGAC_CXX_TYPEOF_UNQUAL],
[AC_CACHE_CHECK(for C++ typeof_unqual, pgac_cv_cxx_typeof_unqual,
[pgac_cv_cxx_typeof_unqual=no
AC_LANG_PUSH(C++)
-for pgac_kw in __typeof_unqual__ typeof_unqual; do
+for pgac_kw in typeof_unqual __typeof_unqual__; do
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[int x = 0;
$pgac_kw(x) y;
diff --git a/configure b/configure
index f69331f0748..5aec0afa9ab 100755
--- a/configure
+++ b/configure
@@ -15084,13 +15084,9 @@ if ${pgac_cv_c_typeof_unqual+:} false; then :
$as_echo_n "(cached) " >&6
else
pgac_cv_c_typeof_unqual=no
-# Test the underscore variant first so that there is a higher chance
-# that clang used for bitcode also supports it, since we don't test
-# that separately.
-#
# Test with a void pointer, because MSVC doesn't handle that, and we
# need that for copyObject().
-for pgac_kw in __typeof_unqual__ typeof_unqual; do
+for pgac_kw in typeof_unqual __typeof_unqual__; do
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15141,7 +15137,7 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-for pgac_kw in __typeof_unqual__ typeof_unqual; do
+for pgac_kw in typeof_unqual __typeof_unqual__; do
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
diff --git a/meson.build b/meson.build
index f7a87edcc94..46bd6b1468a 100644
--- a/meson.build
+++ b/meson.build
@@ -2969,13 +2969,9 @@ endif
# Check if the C compiler understands typeof_unqual or a variant. Define
# HAVE_TYPEOF_UNQUAL if so, and define 'typeof_unqual' to the actual key word.
#
-# Test the underscore variant first so that there is a higher chance
-# that clang used for bitcode also supports it, since we don't test
-# that separately.
-#
# Test with a void pointer, because MSVC doesn't handle that, and we
# need that for copyObject().
-foreach kw : ['__typeof_unqual__', 'typeof_unqual']
+foreach kw : ['typeof_unqual', '__typeof_unqual__']
if cc.compiles('''
int main(void)
{
@@ -3002,7 +2998,7 @@ endforeach
# Check if the C++ compiler understands typeof_unqual or a variant.
if have_cxx
- foreach kw : ['__typeof_unqual__', 'typeof_unqual']
+ foreach kw : ['typeof_unqual', '__typeof_unqual__']
if cxx.compiles('''
int main(void)
{
diff --git a/src/include/c.h b/src/include/c.h
index 29fef2f54e1..8987a121d6a 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -432,6 +432,21 @@ extern "C++"
#define unlikely(x) ((x) != 0)
#endif
+/*
+ * When we call clang to generate bitcode, we might be using configure results
+ * from a different compiler, which might not be fully compatible with the
+ * clang we are using. The fully correct solution would be to run a separate
+ * set of configure tests for that clang-for-bitcode, but that could be very
+ * difficult to implement, and in practice clang supports most things other
+ * compilers support. So this section just contains some hardcoded ugliness
+ * to override some configure results where it is necessary.
+ */
+#if defined(__clang__)
+#if __clang_major__ < 19
+#undef HAVE_TYPEOF_UNQUAL
+#endif
+#endif /* __clang__ */
+
/*
* Provide typeof in C++ for C++ compilers that don't support typeof natively.
* It might be spelled __typeof__ instead of typeof, in which case
[parent: be0d0b457cb6]