GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cfgexpand

Cfgexpand: Consistently align stack variables.

Ensures consistent stack alignment calculation for local variables to fix alignment assertion failures.

This fix in the cfgexpand pass ensures that stack-allocated local variables are consistently aligned. Previously, defer_stack_allocation and expand_one_stack_var_1 used different methods to calculate alignment, causing variables deemed small enough by one function to trigger a large-alignment assertion in the other. The change standardizes alignment computation using align_local_variable.

In Details

The cfgexpand pass previously had two distinct functions, defer_stack_allocation and expand_one_stack_var_1, calculating local variable stack alignment using different logic. This divergence could lead to a situation where a variable was considered small enough for immediate stack allocation by defer_stack_allocation, but its calculated alignment would then fail an assertion in expand_one_stack_var_1. By having both functions use align_local_variable for alignment calculation, this commit resolves the inconsistency and the associated PR target/120192.

For Context
cfgexpand
A GCC pass responsible for expanding Control Flow Graphs (CFGs) and handling stack frame layout, including local variable allocation and alignment.
stack alignment
Ensuring that data on the stack is placed at memory addresses that are multiples of a certain value (e.g., 4, 8, or 16 bytes). This is crucial for performance and correctness on many architectures.
stack allocation
The process of reserving space on the program's call stack for local variables and function call information.
assertion failure
A condition checked by the compiler during development or runtime that, if false, indicates a programming error and typically halts execution.
Filed Under: stackalignmentcompiler