From 2de6675b66388341ba9d71bcaa47c47e87f667b9 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Wed, 11 Mar 2026 13:26:22 +1300
Subject: [PATCH v2 02/19] Provide pg_has_builtin() macro.

The traditional approach of configure/meson problems that define
HAVE__BUILTIN_FOO doesn't work for results that vary across the CC, CXX
and CLANG compilers.  In Clang since early version, and in GCC 10+, you
can test with __has_builtin(__builtin_foo) instead.  This wrapper can be
tested in preprocessor conditions using pg_has_builtin(__builtin_foo).

This approach has a bootstrapping problem, since __has_builtin() itself
was adopted only ~6 years ago by GCC, so it will always evaluate to
false for older GCC versions.  Traditional configure probes therefore
remain useful for well established builtins where the three selected
compilers are unlikely to differ.  This macro is useful for builtins
that were more recently invented, or adopted late by one or the other of
GCC and Clang.
---
 src/include/c.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/include/c.h b/src/include/c.h
index 5b678283469..5c74da5004e 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -116,6 +116,16 @@ extern "C++"
 #define inline
 #endif
 
+/*
+ * Clang and GCC 10+ can test for a builtin's presence.  This can be useful
+ * for builtins that might be present for CC but not CXX or CLANG.
+ */
+#ifdef __has_builtin
+#define pg_has_builtin(x) __has_builtin(x)
+#else
+#define pg_has_builtin(x) 0
+#endif
+
 /*
  * Attribute macros
  *
-- 
2.53.0

