GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
cfgexpand

cfgexpand: Align ASan variable block to stack alignment.

Ensures AddressSanitizer variable allocation respects stack alignment needs.

This commit ensures that the block of variables used by AddressSanitizer (data.asan_alignb) is properly aligned with the stack’s alignment requirements (crtl->stack_alignment_needed). If the stack alignment needed is greater than the current ASan allocation alignment, it could lead to misaligned stack allocations for subsequent data, such as vector modes with large alignment requirements. The change updates data.asan_alignb to the maximum of its current value and the stack alignment needed, preventing potential alignment issues.

In Details

The expand_used_vars function in cfgexpand.cc is modified to set data.asan_alignb to the maximum of its current value and crtl->stack_alignment_needed / BITS_PER_UNIT. This guarantees that the allocation block for ASan-related variables on the stack respects the overall stack alignment requirements dictated by the target's crtl (compiler runtime/control structure). This prevents potential misalignments when the stack alignment is more restrictive than what ASan's default allocation provides, particularly critical for vectorized types.

For Context
cfgexpand
A GCC compiler pass that expands control flow graphs (CFGs) and local variables, preparing the code for subsequent optimization and code generation phases.
AddressSanitizer (ASan)
A memory error detector for C/C++ that finds use-after-free, heap buffer overflows, stack buffer overflows, and use-after-return errors. It instruments code to track memory accesses.
stack alignment
The requirement that memory addresses occupied by the stack frame must be divisible by a certain power of two. This ensures efficient access to data types, especially on modern processors.
BITS_PER_UNIT
A target-specific macro in GCC that defines the number of bits in a 'unit' of memory, typically a byte (8 bits).
vector modes
Data types representing multiple scalar values packed together, typically used for SIMD (Single Instruction, Multiple Data) operations.
Filed Under: asanstackalignmentcompilerbugfix