aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2019-08-13 08:08:27 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-08-13 08:08:27 +0000
commit5b15ac5f0506f3d9c1cf0913024e1c721521f7c0 (patch)
tree016e9d2753a59ec6aa29897d62c9cb658d79c36e /gcc/ada
parent5efb7125030aab3e2622be6de7fbbb18ddfadc8f (diff)
downloadgcc-5b15ac5f0506f3d9c1cf0913024e1c721521f7c0.zip
gcc-5b15ac5f0506f3d9c1cf0913024e1c721521f7c0.tar.gz
gcc-5b15ac5f0506f3d9c1cf0913024e1c721521f7c0.tar.bz2
[Ada] Wrong dispatching call in type with aspect Implicit_Dereference
When a record type with an an access to class-wide type discriminant has aspect Implicit_Dereference, and the discriminant is used as the controlling argument of a dispatching call, the compiler may generate wrong code to dispatch the call. 2019-08-13 Javier Miranda <miranda@adacore.com> gcc/ada/ * sem_res.adb (Resolve_Selected_Component): When the type of the component is an access to a class-wide type and the type of the context is an access to a tagged type the relevant type is that of the component (since in such case we may need to generate implicit type conversions or dispatching calls). gcc/testsuite/ * gnat.dg/tagged3.adb, gnat.dg/tagged3_pkg.adb, gnat.dg/tagged3_pkg.ads: New testcase. From-SVN: r274356
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog8
-rw-r--r--gcc/ada/sem_res.adb15
2 files changed, 23 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index dfc30f2..5e31330 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,11 @@
+2019-08-13 Javier Miranda <miranda@adacore.com>
+
+ * sem_res.adb (Resolve_Selected_Component): When the type of the
+ component is an access to a class-wide type and the type of the
+ context is an access to a tagged type the relevant type is that
+ of the component (since in such case we may need to generate
+ implicit type conversions or dispatching calls).
+
2019-08-13 Ed Schonberg <schonberg@adacore.com>
* exp_aggr.adb (Aggr_Assignment_OK_For_Backend): Preanalyze
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 7a9c85c..b27171f 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -10598,6 +10598,10 @@ package body Sem_Res is
pragma Assert (Found);
Resolve (P, It1.Typ);
+
+ -- In general the expected type is the type of the context, not the
+ -- type of the candidate selected component.
+
Set_Etype (N, Typ);
Set_Entity_With_Checks (S, Comp1);
@@ -10610,6 +10614,17 @@ package body Sem_Res is
if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
Set_Etype (N, Etype (Comp1));
+
+ -- When the type of the component is an access to a class-wide type
+ -- the relevant type is that of the component (since in such case we
+ -- may need to generate implicit type conversions or dispatching
+ -- calls).
+
+ elsif Is_Access_Type (Typ)
+ and then not Is_Class_Wide_Type (Designated_Type (Typ))
+ and then Is_Class_Wide_Type (Designated_Type (Etype (Comp1)))
+ then
+ Set_Etype (N, Etype (Comp1));
end if;
else