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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Earnshaw <rearn...@gcc.gnu.org>:

https://gcc.gnu.org/g:670cfd5fe6433ee8f2e86eedb197d2523dbb033b

commit r15-3588-g670cfd5fe6433ee8f2e86eedb197d2523dbb033b
Author: Richard Earnshaw <rearn...@arm.com>
Date:   Wed Aug 21 16:15:34 2024 +0100

    arm: avoid indirect sibcalls when IP is live [PR116597]

    On Arm only r0-r3 (the argument registers) and IP are available for
    use as an address for an indirect sibcall.  But if all the argument
    registers are used and IP is clobbered during the epilogue, or is used
    to pass closure information, then there is no spare register to hold
    the address and we must reject the sibcall.

    arm_function_ok_for_sibcall did try to handle this, but it did this by
    examining the function declaration.  That doesn't work if the function
    has no prototype, or if the prototype has variadic arguments: we must,
    instead, look at the list of actuals for the call rather than the list
    of formals.

    The old code also worked by laying out all the arguments and then
    trying to add one more integer argument at the end of the list, but
    this missed a corner case where a hole had been left in the argument
    register list due to argument alignment.

    We fix all of this by now scanning the list of actual values to be
    passed and then checking if a core register has been assigned to that
    argument.  If it has, then we record which registers were assigned.
    Once done we then look to see if all the argument registers have been
    assigned and only block the sibcall if that is the case.  This permits
    us to sibcall:

        int (*d)(int, ...);
        int g(void);
        int i () { return d(g(), 2LL);}

    because r1 remains free (the 2LL argument is passed in {r2,r3}).

    gcc/
            PR target/116597
            * config/arm/arm.cc (arm_function_ok_for_sibcall): Use the list of
            actuals for the call, not the list of formals.

    gcc/testsuite/
            PR target/116597
            * gcc.target/arm/pac-sibcall-2.c: New test.
            * gcc.target/arm/pac-sibcall-3.c: New test.

Reply via email to