C++: Fix constant recomputation for changed ADDR_EXPR.
Bug fix ensures constants are recomputed correctly when ADDR_EXPR changes in constexpr evaluations.
This commit fixes a bug where constants were not being recomputed when an ADDR_EXPR changed within constant evaluation contexts. The issue arose because the recomputation logic (recompute_tree_invariant_expr) was only applied to the first ADDR_EXPR encountered, not subsequent ones. The fix involves ensuring unshare_expr is called correctly during placeholder replacement in lookup_placeholder, particularly when shared trees are involved.
In Details
A regression in gcc/cp/constexpr.cc caused ICEs in verify_address due to stale constant evaluations. The problem occurred when multiple ADDR_EXPRs shared a base expression that was later updated. The fix ensures that lookup_placeholder calls unshare_expr when replacing placeholders, preventing the d->changed flag from prematurely evaluating to false and thus missing necessary constant recomputations of subsequent ADDR_EXPRs.
- ADDR_EXPR
- An expression representing the address of an object or function within GCC's internal representation.
- ICE
- Internal Compiler Error. A severe error where the compiler encounters an unexpected condition and terminates, usually indicating a compiler bug.
- Placeholder Expression
- A temporary representation within GCC's IR for an expression that needs further resolution or replacement later in the compilation process.
- Constant Evaluation
- The process where the compiler computes the value of an expression at compile time, typically for
constexprvariables or functions, rather than at runtime.