diff --git a/Include/pyport.h b/Include/pyport.h index c6cc47f7a14103..718a9b50bae103 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -306,16 +306,15 @@ extern "C" { * Usage: * int _Py_HOT_FUNCTION x(void) { return 3; } * - * Issue #28618: This attribute must not be abused, otherwise it can have a + * Issue gh-72804: This attribute must not be abused, otherwise it can have a * negative effect on performance. Only the functions were Python spend most of * its time must use it. Use a profiler when running performance benchmark * suite to find these functions. */ -#if defined(__GNUC__) \ - && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) -#define _Py_HOT_FUNCTION __attribute__((hot)) +#if _Py__has_attribute(hot) +# define _Py_HOT_FUNCTION __attribute__((hot)) #else -#define _Py_HOT_FUNCTION +# define _Py_HOT_FUNCTION #endif // Ask the compiler to always inline a static inline function. The compiler can 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.