IPA fixes a lifetime issue with hash_map in debug expression preparation.
GCC's Interprocedural Analysis (IPA) pass now correctly handles the lifetime of `hash_map` elements when preparing debug expressions, preventing potential data…
This commit resolves a lifetime issue in the Interprocedural Analysis (IPA) pass concerning the use of hash_map::put within prepare_debug_expressions. Previously, dereferencing the result of hash_map::get directly as the second argument to put could lead to data corruption if the hash map resized, invalidating the reference. The fix ensures that the retrieved tree pointer is copied by value before being passed to put, thus guaranteeing its stability even if the hash map reallocates its internal storage.
In Details
This bug fix addresses a subtle lifetime issue within the ipa_param_body_adjustments::prepare_debug_expressions function, specifically involving m_dead_ssa_debug_equiv, a hash_map<tree, tree>. The hash_map::put method, when its second argument is a reference, can lead to undefined behavior if the map rehashes (resizes) during the operation, invalidating the reference to the original data. The previous code directly dereferenced m_dead_ssa_debug_equiv.get(value) which yielded a pointer to the map's internal storage, then passed that dereferenced value (a tree reference) to put. T…
For Context
Compilers have many steps to optimize your code, and one advanced step is called Interprocedural Analysis (IPA). This process looks at how different functions interact to make better optimization decisions. This change fixes a very specific, technical bug in GCC's IPA pass related to how it manages internal data structures (specifically a hash_map) when preparing information for debugging. Imagine a dictionary where you look up a value, and then try to use that value to update another entry, but while you're doing so, the dictionary suddenly rearranges itself and moves everything around. If you were holding a direct 'pointer' to the old location, it would become invalid. This bug was similar: the compiler was temporarily holding onto a reference to data within its internal hash_map while potentially modifying the map in a way that could move that data, leading to errors or corrupted information. The fix ensures that the value is safely copied before being used, preventing this pot…