In (illegal) mutually-dependent type declarations, it is possible for
Etype (Etype (Typ)) to point back to Typ. This patch stops the recursion
in such cases.
gcc/ada/
* sem_util.adb (Process_Type): Stop the recursion.
* exp_aggr.adb (Build_Record_Aggr_Code): Add assertion.
Comp := First (Component_Associations (N));
while Present (Comp) loop
Selector := Entity (First (Choices (Comp)));
+ pragma Assert (Present (Selector));
-- C++ constructors
-- Examine parent type
if Etype (Typ) /= Typ then
+ -- Prevent infinite recursion, which can happen in illegal
+ -- programs. Silently return if illegal. For now, just deal
+ -- with the 2-type cycle case. Larger cycles will get
+ -- SIGSEGV at compile time from running out of stack.
+
+ if Etype (Etype (Typ)) = Typ then
+ if Total_Errors_Detected = 0 then
+ raise Program_Error;
+ else
+ return;
+ end if;
+ end if;
+
Process_Type (Etype (Typ));
end if;