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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Igor Shevlyakov
<[email protected]>:

https://gcc.gnu.org/g:12a68f71e25121cf15277e029896af5e41051e54

commit r17-6561-g12a68f71e25121cf15277e029896af5e41051e54
Author: Igor Shevlyakov <[email protected]>
Date:   Tue Nov 10 11:30:24 2026 -0800

    function: take __builtin_dwarf_cfa from the DRAP in a realigned frame
[PR128611]

    instantiate_new_reg replaced virtual_cfa_rtx with the argument pointer
    plus cfa_offset.  In a frame realigned with a dynamic realign argument
    pointer (DRAP) the argument pointer is at no fixed offset from SP or the
    hard frame pointer.  On x86 it is eliminated to a fake location, the copy
    of the return address pushed after realignment, so __builtin_dwarf_cfa
    returns the wrong address.  On a target that doesn't push such a copy it
    can't be eliminated at all.

    virtual_incoming_args_rtx already uses crtl->args.internal_arg_pointer,
    the DRAP pseudo, in this case: the DRAP holds arg_pointer_rtx +
    in_arg_offset.  Do the same for virtual_cfa_rtx, at offset
    cfa_offset - in_arg_offset.  On x86, the only target that currently
    reaches this path, in_arg_offset is 0; subtracting it keeps the
    instantiation correct for a target where FIRST_PARM_OFFSET is not 0.

    The FRAME_POINTER_CFA_OFFSET branch is left alone.  Of the targets that
    define it, only nvptx also provides a DRAP (TARGET_GET_DRAP_RTX), and
    there is no CFA-based unwinding on PTX to check it against.

    dwarf-cfa-1.c compares the CFA seen by a realigned and a plain function
    called from the same frame.  Without this change it aborts on x86_64
    and i686 whenever the frame is realigned with a DRAP: in the
    -mforce-drap variants of stackalign.exp, and with -m32 unless
    -maccumulate-outgoing-args is given.

    Assisted-by: Claude Opus 5.5
    Acked-by: Uros Bizjak <[email protected]>

    gcc/ChangeLog:

            PR middle-end/128611
            * function.cc (instantiate_new_reg): Instantiate virtual_cfa_rtx
            from the DRAP pseudo in a realigned frame.

    gcc/testsuite/ChangeLog:

            PR middle-end/128611
            * gcc.dg/torture/stackalign/dwarf-cfa-1.c: New test.

    Signed-off-by: Igor Shevlyakov <[email protected]>

Reply via email to