C++: Fix rollback of side effects for nested [[assume]] attributes.
Nested [[assume]] attributes now correctly roll back side effects during constant evaluation.
A bug in the handling of nested [[assume]] attributes during constant evaluation has been fixed. Previously, when one [[assume]] was evaluated within the predicate of another, the side effects of the inner assumption were not correctly rolled back. This led to incorrect state, which is now resolved by properly restoring the previous context after the inner evaluation completes.
In Details
The constexpr_global_ctx in gcc/cp/constexpr.cc stores a pointer to a set of modifiable values for the modifiable_tracker. When [[assume]] is evaluated, the tracker populates this context; upon completion, it should clear it. In nested [[assume]] scenarios, the inner modifiable_tracker's destructor would clear the global pointer, losing the context of the outer [[assume]]. This fix saves the outer tracker's state and restores it upon the inner tracker's destruction.
- [[assume]]
- A C++23 attribute that provides a hint to the compiler that a certain condition is true. It can be used to enable optimizations, but its predicate must be evaluated at compile time.
- constant evaluation
- The process by which the compiler evaluates expressions or function calls at compile time, rather than at runtime. This can enable optimizations and is required for certain language features.
- constexpr_global_ctx
- A global context used during constant evaluation in GCC's C++ front-end to track information, such as pointers to sets of modifiable values.
- modifiable_tracker
- A class within GCC's C++ front-end that manages the tracking of modifiable values during constant evaluation, particularly relevant for attributes like [[assume]].