From be3614c740f91caf593e77b7138e65013fc0487b Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Fri, 13 Dec 2019 09:04:23 +0000 Subject: [PATCH] [Ada] Crash on implicit dereference not made explicit 2019-12-13 Ed Schonberg gcc/ada/ * sem_res.adb (Resolve): IF an entity reference is overloaded because its type has an Implicit_Dereference aspect, we must examine the discriminants of the type to determine whether an explicit dereference must be inserted for use in code generation. Previously this was done for other expressions but not for entity references by themselves. This was sufficient to handle uses of the aspect in container handling and iteration, but not more generally. From-SVN: r279352 --- gcc/ada/ChangeLog | 11 +++++++++++ gcc/ada/sem_res.adb | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b4ed0d57056..9cb8f7951f1 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,14 @@ +2019-12-13 Ed Schonberg + + * sem_res.adb (Resolve): IF an entity reference is overloaded + because its type has an Implicit_Dereference aspect, we must + examine the discriminants of the type to determine whether an + explicit dereference must be inserted for use in code + generation. Previously this was done for other expressions but + not for entity references by themselves. This was sufficient to + handle uses of the aspect in container handling and iteration, + but not more generally. + 2019-12-13 Javier Miranda * exp_disp.ads (Expand_Interface_Thunk): Adding one formal (the diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 11b531610e0..3568a890186 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -2640,17 +2640,43 @@ package body Sem_Res is Set_Etype (N, Expr_Type); -- AI05-0139-2: Expression is overloaded because type has - -- implicit dereference. If type matches context, no implicit - -- dereference is involved. If the expression is an entity, - -- generate a reference to it, as this is not done for an - -- overloaded construct during analysis. + -- implicit dereference. The context may be the one that + -- requires implicit dereferemce. elsif Has_Implicit_Dereference (Expr_Type) then Set_Etype (N, Expr_Type); Set_Is_Overloaded (N, False); - if Is_Entity_Name (N) then + -- If the expression is an entity, generate a reference + -- to it, as this is not done for an overloaded construct + -- during analysis. + + if Is_Entity_Name (N) + and then Comes_From_Source (N) + then Generate_Reference (Entity (N), N); + + -- Examine access discriminants of entity type, + -- to check whether one of them yields the + -- expected type. + + declare + Disc : Entity_Id := + First_Discriminant (Etype (Entity (N))); + + begin + while Present (Disc) loop + exit when Is_Access_Type (Etype (Disc)) + and then Has_Implicit_Dereference (Disc) + and then Designated_Type (Etype (Disc)) = Typ; + + Next_Discriminant (Disc); + end loop; + + if Present (Disc) then + Build_Explicit_Dereference (N, Disc); + end if; + end; end if; exit Interp_Loop; -- 2.30.2