Fix AVR prologue_saves with noreturn and stack arguments
Correctly handles stack arguments in noreturn AVR functions compiled with -mcall-prologues.
A bug in AVR code generation has been fixed where functions marked as noreturn and compiled with -mcall-prologues, which also receive arguments on the stack, produced incorrect code. The prologue_saves mechanism was saving more registers than necessary, leading to an incorrect argument pointer. The fix ensures that prologue_saves is not used in these specific scenarios by modifying sequent_regs_live to return zero for noreturn functions, thus preventing the erroneous register saving.
In Details
This commit addresses PR target/127482 concerning the interaction between -mcall-prologues, noreturn functions, and stack-passed arguments on the AVR target. The issue was that avr_prologue_setup_frame would incorrectly use prologue_saves even for noreturn functions, causing it to save more registers than accounted for by avr_regs_to_save(). This corrupted the stack frame and the argument pointer. The fix involves modifying sequent_regs_live to return 0 registers to save for noreturn, OS_task, and OS_main functions, effectively disabling prologue_saves in these cases and…
- AVR
- A family of microcontrollers developed by Atmel (now Microchip Technology). GCC supports compiling code for these processors.
- noreturn
- A function attribute indicating that the function will not return to its caller. This allows the compiler to perform certain optimizations, such as assuming that control flow after the call will not resume.
- -mcall-prologues
- A GCC target-specific flag for AVR that enables the use of prologue saving mechanisms, which can optimize function entry sequences.
- prologue_saves
- A specific code generation strategy in the AVR backend for saving registers onto the stack at the beginning of a function call.
- argument pointer
- A pointer or register that holds the address of function arguments on the stack or in memory.
- stack frame
- A region of memory on the call stack used to store information for a single function call, including local variables, function parameters, and return addresses.