[arm][PR88167] Fix __builtin_return_address returns invalid address
authorMihail Ionescu <mihail.ionescu@arm.com>
Wed, 8 May 2019 14:36:15 +0000 (14:36 +0000)
committerRichard Earnshaw <rearnsha@gcc.gnu.org>
Wed, 8 May 2019 14:36:15 +0000 (14:36 +0000)
commit69708e0afbf3a3757b9f689bb54acff1d7e8d9ec
treeecab78ea40e90eb3e8088b2bb966d1c675b8e801
parent857c72026ed7d78a7bf92f3d9a3d773f1a5edbc3
[arm][PR88167] Fix __builtin_return_address returns invalid address

This patch fixes a problem with the thumb1 prologue code where the link
register could be unconditionally used as a scratch register even if the
return value was still live at the end of the prologue.

Additionally, the patch improves the code generated when we are not
using many low call-saved registers to make use of any unused call
clobbered registers to help with the saving of high registers that
cannot be pushed directly (quite rare in normal code as the register
allocator correctly prefers low registers).

2019-05-08  Mihail Ionescu  <mihail.ionescu@arm.com>
    Richard Earnshaw  <rearnsha@arm.com>

gcc:

PR target/88167
* config/arm/arm.c (thumb1_prologue_unused_call_clobbered_lo_regs): New
function.
(thumb1_epilogue_unused_call_clobbered_lo_regs): New function.
(thumb1_compute_save_core_reg_mask): Don't force a spare work
register if both the epilogue and prologue can use call-clobbered
regs.
(thumb1_unexpanded_epilogue): Use
thumb1_epilogue_unused_call_clobbered_lo_regs.  Reverse the logic for
picking temporaries for restoring high regs to match that of the
prologue where possible.
(thumb1_expand_prologue): Add any usable call-clobbered low registers to
the list of work registers.  Detect if the return address is still live
at the end of the prologue and avoid using it for a work register if so.
If the return address is not live, add LR to the list of pushable regs
after the first pass.

gcc/testsuite:

PR target/88167
* gcc.target/arm/pr88167-1.c: New test.
* gcc.target/arm/pr88167-2.c: New test.

Co-Authored-By: Richard Earnshaw <rearnsha@arm.com>
From-SVN: r271012
gcc/ChangeLog
gcc/config/arm/arm.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/pr88167-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/pr88167-2.c [new file with mode: 0644]