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 4cfce4e62c, 0af05b5dbb, and 59292f7aac 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 59292f7aac
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
This commit is contained in:
Peter Eisentraut 2026-03-16 18:56:30 +01:00
parent be0d0b457c
commit 63275ce84d
4 changed files with 21 additions and 18 deletions

View file

@ -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;

8
configure vendored
View file

@ -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. */

View file

@ -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)
{

View file

@ -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