Bug 2544649 - GCC crash on s390x when building a C function which uses _Float16/uint16_t, memcpy() and __builtin_bswap16()
Summary: GCC crash on s390x when building a C function which uses _Float16/uint16_t, m...
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 44
Hardware: s390x
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2026-10-01 15:04 UTC by Victor Stinner
Modified: 2026-10-01 17:48 UTC (History)
12 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)
reproducer.c: C program to reproduce the GCC crash (331 bytes, text/plain)
2026-10-01 15:07 UTC, Victor Stinner
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 127692 0 None None None 2026-10-01 15:47:50 UTC

Description Victor Stinner 2026-10-01 15:04:45 UTC
bug.c file to reproduce the crash:
----------
#include <string.h>
#include <stdint.h>

void
PyFloat_Pack2(double x, char *data, int le)
{
    _Float16 y = (_Float16)x;
    if (!le) {
        uint16_t word;
        memcpy(&word, &y, 2);
        word = __builtin_bswap16(word);
        memcpy(data, &word, 2);
    }
    else {
        memcpy(data, &y, sizeof(_Float16));
    }
}
----------

GCC crash with -O1 or higher, but it doesn't crash with -O0 or -Og.

Reproducible: Always

Steps to Reproduce:
1. Create bug.c
2. gcc -O1 -o bug.o -c bug.c
Actual Results:
Build with gcc 16.2.1 (Fedora package gcc-16.2.1-2.fc44.s390x):
----------
$ gcc -O1 -o bug.o -c bug.c
during RTL pass: split1
bug.c: In function ‘PyFloat_Pack2’:
bug.c:17:1: internal compiler error: Segmentation fault
   17 | }
      | ^
/usr/libexec/gcc/s390x-redhat-linux/16/cc1 -quiet bug.c -quiet -dumpbase bug.c -dumpbase-ext .c -mtune=z14 -march=z13 -m64 -mzarch -O1 -o /tmp/cc0XMx28.s
Please submit a full bug report, with preprocessed source.
See <https://bugzilla.redhat.com/> for instructions.
Preprocessed source stored into /tmp/cceEi1QY.out file, please attach this to your bugreport.
----------

Expected Results:
No crash.

Additional Information:
$ uname -a
Linux fedora-stable 7.2.5-200.fc44.s390x #1 SMP PREEMPT Fri Sep 11 15:37:18 UTC 2026 s390x GNU/Linux

$ sudo virt-what
ibm_systemz
ibm_systemz-zvm

Comment 1 Victor Stinner 2026-10-01 15:07:12 UTC
Created attachment 2159407 [details]
reproducer.c: C program to reproduce the GCC crash

Comment 2 Victor Stinner 2026-10-01 15:09:00 UTC
Sorry, I forgot to mention that, so far, I only reproduced the crash on s390x architecture.

Comment 3 Victor Stinner 2026-10-01 17:48:56 UTC
Oh, clang also miscompiles this code (but don't crash): https://github.com/llvm/llvm-project/issues/228151

In Python, I just merged a workaround. Replace:
---
            _Float16 y = (...);
            uint16_t word;
            memcpy(&word, &y, 2);
            word = __builtin_bswap16(word);
            memcpy(data, &word, 2);
---

with:
---
            _Float16 y = (...);
            char buffer[2];
            memcpy(buffer, &y, 2);
            data[0] = buffer[1];
            data[1] = buffer[0];
---

See the Python change: https://github.com/python/cpython/commit/c7a79bd2f4d3dd3bcaebd77c47f07d1feabe320a


Note You need to log in before you can comment on or make changes to this bug.