ada: Fix incorrect resolution of overloaded function call in instance
The problem occurs when the function call is the operand of an equality
operator, the type used to do the comparison is declared outside of the
generic construct but visible inside it, and this generic construct also
declares two functions with the same profile except for the result type,
one result type being the aforementioned type, the other being derived
from this type but not visible inside the generic construct. When the
second operand is either a literal or also overloaded, the call may be
resolved to the second function instead of the first in instances.
gcc/ada/
* gen_il-fields.ads (Opt_Field_Enum): Add Compare_Type.
* gen_il-gen-gen_nodes.adb (N_Op_Eq): Likewise.
(N_Op_Ge): Likewise.
(N_Op_Gt): Likewise.
(N_Op_Le): Likewise.
(N_Op_Lt): Likewise.
(N_Op_Ne): Likewise.
* sinfo.ads (Compare_Type): Document new field.
* sem_ch4.adb (Analyze_Comparison_Equality_Op): If the entity is
already present, set the Compare_Type on overloaded operands if it
is present on the node.
* sem_ch12.adb (Check_Private_View): Look into the Compare_Type
instead of the Etype for comparison operators.
(Copy_Generic_Node): Remove obsolete code for comparison
operators.
(Save_Global_References.Save_References): Do not walk into the
descendants of N_Implicit_Label_Declaration nodes.
(Save_Global_References.Set_Global_Type): Look into the
Compare_Type instead of the Etype for comparison operators.
* sem_res.adb (Resolve_Comparison_Op): Set Compare_Type.
(Resolve_Equality_Op): Likewise.