https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128640

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by hongtao Liu
<[email protected]>:

https://gcc.gnu.org/g:66c5f88d6aa2687e1bc76dfc2cddc331b7e3ee5e

commit r15-11734-g66c5f88d6aa2687e1bc76dfc2cddc331b7e3ee5e
Author: liuhongt <[email protected]>
Date:   Wed Nov 11 23:06:28 2026 -0800

    i386: Use classify_argument for unnamed 256/512-bit vector args [PR128640]

    Unnamed 256-bit and 512-bit vector arguments must be passed on the
    stack, since the register save area set up by a variadic callee only
    holds 16 bytes per SSE register.  function_arg_advance_64,
    function_arg_64 and ix86_gimplify_va_arg implement this rule with an
    explicit check for the 256-bit and 512-bit vector modes.

    The explicit mode check is not enough.  Whether an argument goes in a
    single YMM/ZMM register is decided by classify_argument (SSE followed
    by all SSEUP), and that classification also applies to BLKmode
    aggregates without a vector mode, e.g. a union whose widest member is
    a 256-bit or 512-bit vector.  Such unnamed arguments slip past the
    mode check: the caller passes them in %ymm/%zmm, and va_arg reads them
    from consecutive 16-byte slots of the register save area, which yields
    wrong upper lanes, or segfaults on an aligned 32/64-byte load from a
    16-byte aligned slot.

    Replace the explicit mode check with classify_argument: it only returns
    more than 2 classes for SSE followed by all SSEUP, i.e. exactly when
    the argument would be passed in a single 256-bit or 512-bit vector
    register.  Assert that invariant in the classify_argument wrapper with
    checking enabled.

    gcc/ChangeLog:

            PR target/128640
            * config/i386/i386.cc (classify_argument): In the wrapper,
            assert that more than 2 classes means SSE followed by all SSEUP.
            (function_arg_advance_64): Use classify_argument instead of an
            explicit vector mode check to pass unnamed 256-bit and 512-bit
            vector arguments on stack.
            (function_arg_64): Likewise.
            (ix86_gimplify_va_arg): Likewise.

    gcc/testsuite/ChangeLog:

            PR target/128640
            * gcc.target/i386/pr128640-1.c: New test.
            * gcc.target/i386/pr128640-2.c: New test.
            * gcc.target/i386/pr128640-3.c: New test.

    (cherry picked from commit 19c7fe8874c52e3452379e87ceaf039de1ae1249)

Reply via email to