aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-12-13 09:04:23 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-12-13 09:04:23 +0000
commitbe3614c740f91caf593e77b7138e65013fc0487b (patch)
tree04f944289cd83f4a6cf88d46217dcfcb4de75667 /gcc/ada
parent20dc266e5a178fd87bb8ae6ebbf63e391f74e9b0 (diff)
downloadgcc-be3614c740f91caf593e77b7138e65013fc0487b.zip
gcc-be3614c740f91caf593e77b7138e65013fc0487b.tar.gz
gcc-be3614c740f91caf593e77b7138e65013fc0487b.tar.bz2
[Ada] Crash on implicit dereference not made explicit
2019-12-13 Ed Schonberg <schonberg@adacore.com> 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
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog11
-rw-r--r--gcc/ada/sem_res.adb36
2 files changed, 42 insertions, 5 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index b4ed0d5..9cb8f79 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-13 Ed Schonberg <schonberg@adacore.com>
+
+ * 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 <miranda@adacore.com>
* 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 11b5316..3568a89 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;