aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2024-07-02 00:42:12 +0000
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-08-01 17:14:38 +0200
commit54d6ce3f067f529e2dbfe237a12e5b65548e298c (patch)
treed7d72abf6452ee429751b53bdf2b06273c425d72
parent679f75ed378bec55dc7c34716c0cc502d69a0255 (diff)
downloadgcc-54d6ce3f067f529e2dbfe237a12e5b65548e298c.zip
gcc-54d6ce3f067f529e2dbfe237a12e5b65548e298c.tar.gz
gcc-54d6ce3f067f529e2dbfe237a12e5b65548e298c.tar.bz2
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.
-rw-r--r--gcc/ada/sem_attr.adb37
1 files changed, 36 insertions, 1 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 5720e5e..a5c90e3 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