diff options
author | Bob Duff <duff@adacore.com> | 2023-01-30 11:25:08 -0500 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-22 10:44:07 +0200 |
commit | df0ac6e158727064dd089be9051a82c26bd66880 (patch) | |
tree | 13fdb944281be2a925fef0f464c5d15f4fbdacd0 | |
parent | 16df2790a58ebbeb949ffb790ebee7f6ed31936d (diff) | |
download | gcc-df0ac6e158727064dd089be9051a82c26bd66880.zip gcc-df0ac6e158727064dd089be9051a82c26bd66880.tar.gz gcc-df0ac6e158727064dd089be9051a82c26bd66880.tar.bz2 |
ada: prevent infinite recursion in Collect_Types_In_Hierarchy
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.
-rw-r--r-- | gcc/ada/exp_aggr.adb | 1 | ||||
-rw-r--r-- | gcc/ada/sem_util.adb | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index fe61e0e..58831bd 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -3837,6 +3837,7 @@ package body Exp_Aggr is Comp := First (Component_Associations (N)); while Present (Comp) loop Selector := Entity (First (Choices (Comp))); + pragma Assert (Present (Selector)); -- C++ constructors diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 1d8d4fc..9cf2195 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6235,6 +6235,19 @@ package body Sem_Util is -- 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; |