diff mbox series

[Ada] Fix crash on quantified expression in expression function

Message ID 20200710094420.GA35314@adacore.com
State New
Headers show
Series [Ada] Fix crash on quantified expression in expression function | expand

Commit Message

Pierre-Marie de Rodat July 10, 2020, 9:44 a.m. UTC
The problem is that the compiler freezes the iterator type associated
with a given type in the body of an expression function that contains
a quantified expression for this type and happens to be the completion
of a previous declaration.   The reason is that Freeze_Expr_Types does
not see that the iterator type is referenced by the expression.

The patch also changes Write_Field24_Name to also display the field as
the Related_Expression for an E_Loop_Parameter entity.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* einfo.adb (Write_Field24_Name): Handle E_Loop_Parameter.
	* freeze.adb (Freeze_Expr_Types): Freeze the iterator type used as
	Default_Iterator of the name of an N_Iterator_Specification node.
diff mbox series

Patch

diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb
--- a/gcc/ada/einfo.adb
+++ b/gcc/ada/einfo.adb
@@ -10969,6 +10969,7 @@  package body Einfo is
 
          when Type_Kind
             | E_Constant
+            | E_Loop_Parameter
             | E_Variable
          =>
             Write_Str ("Related_Expression");


diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -7990,6 +7990,22 @@  package body Freeze is
            and then Nkind (Parent (Node)) = N_Explicit_Dereference
          then
             Check_And_Freeze_Type (Designated_Type (Etype (Node)));
+
+         --  An iterator specification freezes the iterator type, even though
+         --  that type is not attached to an entity in the construct.
+
+         elsif Nkind (Node) in N_Has_Etype
+           and then Nkind (Parent (Node)) = N_Iterator_Specification
+           and then Node = Name (Parent (Node))
+         then
+            declare
+               Iter : constant Node_Id :=
+                           Find_Aspect (Etype (Node), Aspect_Default_Iterator);
+            begin
+               if Present (Iter) then
+                  Check_And_Freeze_Type (Etype (Expression (Iter)));
+               end if;
+            end;
          end if;
 
          --  No point in posting several errors on the same expression