From b9d3c64fd29058870d72a23432158f53f304ecbc Mon Sep 17 00:00:00 2001 From: Shanzhi Chen Date: Fri, 6 Nov 2026 10:08:54 +0800 Subject: [PATCH 1/4] Enable `__attribute__((hot))` for Clang The history of compiler support for the relevant features is as follows. * GCC introduced `__attribute__((hot))` in GCC 4.3.0. * https://gcc.gnu.org/pipermail/gcc-patches/2017-July/478580.html * GCC has supported for `__has_attribute()` since GCC 5. * https://gcc.gnu.org/gcc-5/changes.html * Clang has supported `__attribute__((hot))` since Clang 3.2. * https://github.com/llvm/llvm-project/commit/29c2b4330ce07a7af7452cf3ad2528d0e31952b0 * Clang has supported `__has_attribute()` since Clang 2.9. * https://github.com/llvm/llvm-project/commit/274a70ed7f4315c83273173fce4c3b0e097958d6 * By default, Clang defines `__GNUC__` as 4, `__GNUC_MINOR__` as 2, and `__GNUC_PATCHLEVEL__` as 1. * https://github.com/llvm/llvm-project/issues/99804 Therefore, `__attribute__((hot))` is not enabled when building CPython with Clang's default configuration. And we can use `_Py__has_attribute(hot)` or `GCC version >= 4.3` to determine whether the hot attribute is supported, and enable this attribute for Clang and other compilers that support it. --- Include/pyport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/pyport.h b/Include/pyport.h index c6cc47f7a14103..abdaeb82272939 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -311,7 +311,7 @@ extern "C" { * its time must use it. Use a profiler when running performance benchmark * suite to find these functions. */ -#if defined(__GNUC__) \ +#if _Py__has_attribute(hot) || defined(__GNUC__) \ && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) #define _Py_HOT_FUNCTION __attribute__((hot)) #else From f2f41ebd4d5ba329639abc190bba62fe04091dc1 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:01:15 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst diff --git a/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst b/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst new file mode 100644 index 00000000000000..4254bf06399931 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst @@ -0,0 +1 @@ +Enable the use of `__attribute__((hot))` when building CPython with Clang and other compilers that support it. From b264b7957b146b43a9e39bfef602db549f60aa8f Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:16:32 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2026-11-06-09-16-30.gh-issue-161467.oSuzx_.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2026-11-06-09-16-30.gh-issue-161467.oSuzx_.rst diff --git a/Misc/NEWS.d/next/Build/2026-11-06-09-16-30.gh-issue-161467.oSuzx_.rst b/Misc/NEWS.d/next/Build/2026-11-06-09-16-30.gh-issue-161467.oSuzx_.rst new file mode 100644 index 00000000000000..ae34c60e989ead --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-11-06-09-16-30.gh-issue-161467.oSuzx_.rst @@ -0,0 +1 @@ +Enable the use of ``__attribute__((hot))`` when building CPython with Clang and other compilers that support it. From 76481b7ec3785b0290d47393bf5d39f998d30006 Mon Sep 17 00:00:00 2001 From: Shanzhi Chen Date: Fri, 6 Nov 2026 17:21:30 +0800 Subject: [PATCH 4/4] Remove unnecessary NEWS entry --- .../next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst diff --git a/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst b/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst deleted file mode 100644 index 4254bf06399931..00000000000000 --- a/Misc/NEWS.d/next/Build/2026-11-06-09-01-13.gh-issue-161467.LoaQY2.rst +++ /dev/null @@ -1 +0,0 @@ -Enable the use of `__attribute__((hot))` when building CPython with Clang and other compilers that support it.