https://gcc.gnu.org/g:54d6ce3f067f529e2dbfe237a12e5b65548e298c
commit r15-2633-g54d6ce3f067f529e2dbfe237a12e5b65548e298c Author: Gary Dismukes <dismu...@adacore.com> Date: Tue Jul 2 00:42:12 2024 +0000 ada: Crash on access attribute with overloaded prefix denoting reference object The compiler fails to accept an access attribute where the prefix is the name of an object of a user-defined reference type, and is not prepared to deal with the possibility of overloaded prefixes other than subprogram cases. Such a prefix can either represent the reference object directly, or it can be interpreted as an implicit dereferencing of the object's reference value, depending on the expected type. Special handling for this kind of prefix is added alongside the normal handling for overloaded prefixes of access attributes. gcc/ada/ * sem_attr.adb (Resolve_Attribute, Attribute_*Access): Resolve overloaded prefixes that denote objects of reference types, determining whether to use the prefix object directly, or expand it as an explicit dereference. Diff: --- gcc/ada/sem_attr.adb | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 5720e5e93572..a5c90e3f36de 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -11267,7 +11267,42 @@ package body Sem_Attr is if Is_Overloaded (P) then Get_First_Interp (P, Index, It); while Present (It.Nam) loop - if Type_Conformant (Designated_Type (Typ), It.Nam) then + + -- Overloaded object names can occur when user-defined + -- references are involved. The prefix can be interpreted + -- as either just an object of the reference type, or an + -- implicit dereferencing of such an object. + + if Is_Object (It.Nam) then + if Covers (Designated_Type (Typ), Etype (It.Typ)) then + + -- If the interpretation is a discriminant for an + -- implicit dereference, then build the dereference + -- and resolve the rewritten attribute recursively. + + if Ekind (It.Nam) = E_Discriminant + and then Has_Implicit_Dereference (It.Nam) + then + Build_Explicit_Dereference + (P, Get_Reference_Discriminant (Etype (P))); + Resolve_Attribute (N, Typ); + + return; + end if; + + -- The prefix is definitely NOT overloaded anymore + -- at this point, so we reset the Is_Overloaded + -- flag to avoid any confusion when reanalyzing + -- the node. + + Set_Is_Overloaded (P, False); + Set_Is_Overloaded (N, False); + Generate_Reference (Entity (P), P); + + exit; + end if; + + elsif Type_Conformant (Designated_Type (Typ), It.Nam) then Set_Entity (P, It.Nam); -- The prefix is definitely NOT overloaded anymore at