Commit be3614c7 by Ed Schonberg Committed by Pierre-Marie de Rodat

[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
parent 20dc266e
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> 2019-12-13 Javier Miranda <miranda@adacore.com>
* exp_disp.ads (Expand_Interface_Thunk): Adding one formal (the * exp_disp.ads (Expand_Interface_Thunk): Adding one formal (the
......
...@@ -2640,17 +2640,43 @@ package body Sem_Res is ...@@ -2640,17 +2640,43 @@ package body Sem_Res is
Set_Etype (N, Expr_Type); Set_Etype (N, Expr_Type);
-- AI05-0139-2: Expression is overloaded because type has -- AI05-0139-2: Expression is overloaded because type has
-- implicit dereference. If type matches context, no implicit -- implicit dereference. The context may be the one that
-- dereference is involved. If the expression is an entity, -- requires implicit dereferemce.
-- generate a reference to it, as this is not done for an
-- overloaded construct during analysis.
elsif Has_Implicit_Dereference (Expr_Type) then elsif Has_Implicit_Dereference (Expr_Type) then
Set_Etype (N, Expr_Type); Set_Etype (N, Expr_Type);
Set_Is_Overloaded (N, False); 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); 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; end if;
exit Interp_Loop; exit Interp_Loop;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment