]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: exp_util.adb: prevent infinite loop in case of broken code
authorGhjuvan Lacambre <lacambre@adacore.com>
Wed, 2 Jul 2025 07:11:03 +0000 (09:11 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 22 Jul 2025 10:08:40 +0000 (12:08 +0200)
A recent commit modified exp_util.adb in order to fix the selection of
Finalize subprograms in the case of untagged objects.
This introduced regressions for GNATSAS in fixedbugs by causing
GNAT2SCIL to loop over the same type over and over in case of broken
code.
We fix this by simply checking that the loop is making progress, and if
it doesn't, assume that we're done.

gcc/ada/ChangeLog:

* exp_util.adb (Finalize_Address): Prevent infinite loop

gcc/ada/exp_util.adb

index 90de6962a1bc5dbe013ac35acd7980a1c0b3d2a4..b3dbe98e02bd1375362735ab5e25cf45417e8573 100644 (file)
@@ -6081,12 +6081,17 @@ package body Exp_Util is
 
          else
             declare
-               Root : constant Entity_Id := Underlying_Type (Root_Type (Btyp));
+               Root      : constant Entity_Id :=
+                 Underlying_Type (Root_Type (Btyp));
+               Prev_Utyp : Entity_Id := Empty;
             begin
                if Is_Protected_Type (Root) then
                   Utyp := Corresponding_Record_Type (Root);
                else
-                  while No (TSS (Utyp, TSS_Finalize_Address)) loop
+                  while No (TSS (Utyp, TSS_Finalize_Address))
+                    and then Utyp /= Prev_Utyp
+                  loop
+                     Prev_Utyp := Utyp;
                      Utyp := Underlying_Type (Base_Type (Etype (Utyp)));
                   end loop;
                end if;