x86: Never turn on stack realignment for zero frame size
Fixes stack realignment issues in leaf functions with zero frame size on x86.
This commit prevents the x86 backend from enabling stack realignment for leaf functions that have a zero frame size. Such functions, when performing over-aligned stack accesses through user-casted pointers, could incorrectly trigger stack realignment. This led to an assertion failure in the function epilogue. The fix ensures that stack realignment is only disabled in such cases, aligning with the absence of stack slots.
In Details
For x86 leaf functions with zero frame size, ix86_finalize_stack_frame_flags recomputes stack_realign based on stack access alignments. If a user casts the stack pointer to an over-aligned type (e.g., struct S *p = (struct S *) (sp - 128); where S is 64-byte aligned), this can lead to stack_realign being turned on incorrectly. Since there are no stack slots, such over-alignment is artificial. The patch modifies the logic to only allow recomputation to turn stack realignment *off* for these cases, preventing the stack_realign_finalized assertion trip.
- stack realignment
- A feature that adjusts the stack pointer alignment to match the requirements of specific data types or instructions, typically for performance or correctness.
- leaf function
- A function that does not call any other functions.
- frame size
- The amount of space allocated on the stack for local variables and function arguments.
- epilogue
- The sequence of instructions at the end of a function that cleans up the stack frame and returns control to the caller.
- assertion failure
- An error that occurs when a program's internal consistency check (an assertion) fails, indicating a bug or unexpected state.