GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match.pd

match.pd: Disable A ? B : B folding for C++ FE COND_EXPRs with bit-fields

Prevent folding of conditional expressions with bit-fields to avoid compiler ICEs.

This commit disables a specific folding optimization in match.pd when dealing with C++ frontend COND_EXPRs that involve bit-fields. The C++ frontend can generate COND_EXPRs where operands are bit-fields, which are often unpromoted. An optimization pass, cp_fully_fold, was incorrectly folding these expressions before type promotion occurred, leading to an invalid intermediate representation. This invalid state would later cause a compiler Internal Compiler Error (ICE) during type verification. The fix modifies cp_fold to promote bit-field operands within COND_EXPR before folding, ensuring the expression is valid before optimization passes encounter it.

In Details

The match.pd pattern matching code was incorrectly folding C++ COND_EXPRs containing bit-fields. The C++ frontend (cp) uses TREE_TYPE on COND_EXPR for promotion, but might use unpromoted types for its operands (e.g., if the COND_EXPR is itself an operand to something else). Before gimplification, cp_fully_fold might cache an invalid, unpromoted COND_EXPR. Subsequent calls to cp_fold_r would modify this cached expression, leading to an ICE. This patch modifies cp_fold to perform promotion on COND_EXPR operands if they are bit-fields *before* folding occurs, aligning with…

For Context
match.pd
A file within GCC that likely contains pattern-matching rules or definitions used by the compiler's optimization passes.
COND_EXPR
An internal GCC representation for a ternary conditional operator (e.g., condition ? value_if_true : value_if_false).
bit-field
A member of a structure that occupies a specified number of bits, allowing for more compact data storage.
C++ FE (Frontend)
The part of the GCC compiler responsible for parsing and analyzing C++ source code, converting it into an internal representation.
ICE (Internal Compiler Error)
An unrecoverable error that occurs within the compiler itself during the compilation process, indicating a bug in the compiler.
gimplification
A GCC optimization pass that converts the compiler's high-level intermediate representation (GENERIC) into a lower-level representation (GIMPLE).
Filed Under: c++optimizationbit-fieldICE