[Python-checkins] bpo-41875: Use __builtin_unreachable when possible (GH-22433)

Dong-hee Na webhook-mailer at python.org
Mon Sep 28 16:41:33 EDT 2020


https://github.com/python/cpython/commit/24ba3b0df5e5f2f237d7b23b4017ba12f16320ae
commit: 24ba3b0df5e5f2f237d7b23b4017ba12f16320ae
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-09-29T05:41:23+09:00
summary:

bpo-41875: Use __builtin_unreachable when possible (GH-22433)

files:
A Misc/NEWS.d/next/Build/2020-09-28-21-56-51.bpo-38249.uzMCaZ.rst
M Include/pymacro.h

diff --git a/Include/pymacro.h b/Include/pymacro.h
index 856cae774d61c..202b936d964f0 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -118,7 +118,9 @@
         "We've reached an unreachable state. Anything is possible.\n" \
         "The limits were in our heads all along. Follow your dreams.\n" \
         "https://xkcd.com/2200")
-#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+#  define Py_UNREACHABLE() __builtin_unreachable()
+#elif defined(__clang__) || defined(__INTEL_COMPILER)
 #  define Py_UNREACHABLE() __builtin_unreachable()
 #elif defined(_MSC_VER)
 #  define Py_UNREACHABLE() __assume(0)
diff --git a/Misc/NEWS.d/next/Build/2020-09-28-21-56-51.bpo-38249.uzMCaZ.rst b/Misc/NEWS.d/next/Build/2020-09-28-21-56-51.bpo-38249.uzMCaZ.rst
new file mode 100644
index 0000000000000..3e409ec2e7c20
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2020-09-28-21-56-51.bpo-38249.uzMCaZ.rst
@@ -0,0 +1,2 @@
+Update :c:macro:`Py_UNREACHABLE` to use __builtin_unreachable() if only the
+compiler is able to use it. Patch by Dong-hee Na.



More information about the Python-checkins mailing list