https://github.com/python/cpython/commit/c7a79bd2f4d3dd3bcaebd77c47f07d1feabe320a
commit: c7a79bd2f4d3dd3bcaebd77c47f07d1feabe320a
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-01T16:19:26Z
summary:

gh-158567: Workaround GCC crash in PyFloat_Pack2() (#158568)

Avoid __builtin_bswap16() with _Float16 on s390x.

files:
M Objects/floatobject.c

diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d3ae337236a693..5095da01e45dd2 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1907,10 +1907,20 @@ PyFloat_Pack2(double x, char *data, int le)
         }
 
         if ((_PY_FLOAT_LITTLE_ENDIAN && !le) || (_PY_FLOAT_BIG_ENDIAN && le)) {
+#if defined(__s390x__) && defined(__GNUC__)
+            // gh-158567: Workaround GCC crash on s390x.
+            // Avoid __builtin_bswap16() with _Float16.
+            // https://bugzilla.redhat.com/show_bug.cgi?id=2544649
+            char buffer[2];
+            memcpy(buffer, &y, 2);
+            data[0] = buffer[1];
+            data[1] = buffer[0];
+#else
             uint16_t word;
             memcpy(&word, &y, 2);
             word = _Py_bswap16(word);
             memcpy(data, &word, 2);
+#endif
         }
         else {
             memcpy(data, &y, sizeof(_Float16));

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to