GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ipa-prop

ipa-prop: Add missing checks for byte boundary alignment

Ensures bit offsets align to byte boundaries in aggregate constant calculations, fixing a bug in constant propagation.

This change adds missing checks in the ipa-prop pass to ensure that bit offsets align to byte boundaries when calculating aggregate constants. Previously, the pass could incorrectly return a constant value even if the requested offset was not on a byte boundary, leading to potential issues in constant propagation. The fix includes adding these checks to ipcp_get_aggregate_const and a bounds check.

In Details

The ipa-prop pass, specifically within ipcp_get_aggregate_const and ipcp_modif_dom_walker::before_dom_children, was not validating that bit offsets align to byte boundaries when determining if an aggregate load could result in a known constant. This commit adds the necessary checks to prevent incorrect constant propagation when dealing with bitfields or non-byte-aligned access within aggregates. The fix ensures that computed constants correspond to correctly aligned memory locations, preventing subtle bugs related to aggregate layout.

For Context
ipa-prop
Interprocedural Analysis (IPA) constant propagation. A compiler optimization pass that propagates constant values across function calls to simplify code.
aggregate
A data structure in C and other languages that groups together multiple members, such as structs or unions. Accessing members within aggregates can involve byte or bit offsets.
constant propagation
An optimization that replaces expressions with their constant values where possible. This can simplify code and enable further optimizations.
bit offset
The position of a bit within a larger data type, often measured in bits from the start of the data type. This is distinct from a byte offset.
Filed Under: optimizationbugfix