Ada: Fix infinite loop on reduction expression with -gnatVa
Resolves an infinite loop in Ada's reduction expression analysis when the -gnatVa flag is used.
A regression in the Ada compiler’s analysis of reduction expressions, triggered by the -gnatVa flag, caused an infinite loop due to invalid tree sharing. This commit prevents the Relocate_Node function from being called on the original, unanalyzed tree, thus fixing the loop and the underlying invalid sharing.
In Details
This commit fixes a regression in the Ada front-end's attribute resolution, specifically for the Reduce attribute. An invalid tree sharing in the analysis of reduction expressions, exacerbated by the -gnatVa flag, led to an infinite loop. The fix in Resolve_Attribute prevents Relocate_Node from operating on the unanalyzed tree, breaking the erroneous sharing cycle.
- reduction expression
- In programming, a reduction expression (or fold) combines elements of a sequence into a single value using an associative operation. For example, summing a list of numbers is a reduction.
- -gnatVa
- A compiler flag for GNAT (the Ada compiler part of GCC) that enables extensive runtime checking of various aspects of the program, including semantic analysis, which can catch errors but also incur performance overhead.
- tree sharing
- In compiler construction, tree sharing refers to a technique where identical sub-expressions or data structures are represented by a single instance in memory to save space and potentially speed up processing. Invalid or erroneous tree sharing can lead to incorrect program behavior or compiler bugs.
- attribute resolution
- In Ada, attribute resolution is the process by which the compiler determines the meaning and type of intrinsic attributes (like
.all,.first,.length) applied to types or objects.