C++: Represent aggregate subobjects after std::destroy_at as void_node
Fixes incorrect lifetime tracking for aggregate subobjects destroyed via std::destroy_at in constant evaluation.
This change ensures that aggregate subobjects destroyed using std::destroy_at are correctly marked as outside their lifetime during constant evaluation. Previously, only a normal CONSTRUCTOR was recorded, leading to incorrect std::is_within_lifetime checks. By using void_node for these cases, similar to scalar subobjects, the compiler now accurately reflects the object’s state, preventing potential runtime errors. The fix is applied to aggregate types but excludes CLOBBER_OBJECT_START and CLOBBER_STORAGE_START to avoid breaking existing functionality.
In Details
This commit addresses a bug in constant evaluation related to std::destroy_at on aggregate types. When std::destroy_at is used on an aggregate, the current logic for constant evaluation in cxx_eval_store_expression incorrectly treated the destruction as a normal CONSTRUCTOR, instead of marking the object as invalid. This change modifies cxx_eval_store_expression to use void_node for aggregate subobjects after CLOBBER_OBJECT_END, aligning with the handling of scalar subobjects and ensuring correct lifetime tracking during constant evaluation.
- std::destroy_at
- A C++ function that destroys an object at a given address without calling its destructor if it's a complete object. It's often used for specific lifetime management scenarios.
- aggregate subobjects
- Parts of an aggregate type (like a struct or class) that are themselves objects, distinct from the overall aggregate.
- constant evaluation
- The process where the compiler evaluates expressions at compile time, rather than at runtime. This is crucial for compile-time polymorphism and static initialization.
- void_node
- A special internal representation in GCC's constant evaluation to signify an uninitialized or invalid value, effectively marking an object as outside of its valid lifetime.
- CLOBBER_OBJECT_END
- An internal marker used during constant evaluation to indicate the end of an object's lifetime, often coinciding with its destruction.