]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix infinite loop in compilation of illegal code
authorYannick Moy <moy@adacore.com>
Tue, 20 Jul 2021 11:59:19 +0000 (13:59 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 22 Sep 2021 15:01:46 +0000 (15:01 +0000)
gcc/ada/

* atree.adb (Rewrite): Fix parent node of shared aspects.
* atree.ads (Rewrite): Add ??? comment on incorrect
documentation.
* einfo-utils.adb (Known_Esize): Fix logic.
* sem_ch13.adb (Alignment_Check_For_Size_Change,
Analyze_Attribute_Definition_Clause): Protect against unset
Size.

gcc/ada/atree.adb
gcc/ada/atree.ads
gcc/ada/einfo-utils.adb
gcc/ada/sem_ch13.adb

index 540d4ff74af385840192f4a6f120e13161c82638..d69d4037ebce7963c64597dbcc73c10550675fcf 100644 (file)
@@ -2025,10 +2025,16 @@ package body Atree is
 
          --  Both the old and new copies of the node will share the same list
          --  of aspect specifications if aspect specifications are present.
+         --  Restore the parent link of the aspect list to the old node, which
+         --  is the one linked in the tree.
 
          if Old_Has_Aspects then
-            Set_Aspect_Specifications
-              (Sav_Node, Aspect_Specifications (Old_Node));
+            declare
+               Aspects : constant List_Id := Aspect_Specifications (Old_Node);
+            begin
+               Set_Aspect_Specifications (Sav_Node, Aspects);
+               Set_Parent (Aspects, Old_Node);
+            end;
          end if;
       end if;
 
index 6fb5aa6c2b6fb24d920ea0ed28e2f051c1c08f5b..94e589e70ac63656191822285eb096d1d4e553e2 100644 (file)
@@ -501,6 +501,7 @@ package Atree is
    --  the contents of these two nodes fixing up the parent pointers of the
    --  replaced node (we do not attempt to preserve parent pointers for the
    --  original node). Neither Old_Node nor New_Node can be extended nodes.
+   --  ??? The above explanation is incorrect, instead Copy_Node is called.
    --
    --  Note: New_Node may not contain references to Old_Node, for example as
    --  descendants, since the rewrite would make such references invalid. If
index 15bd9e885b27d8b06bdaa45ca46ed16ab3609b1d..cbd957bd9b99e810aabb63370069c4a5c20949e6 100644 (file)
@@ -414,8 +414,7 @@ package body Einfo.Utils is
       if Use_New_Unknown_Rep then
          return not Field_Is_Initial_Zero (E, F_Esize);
       else
-         return Esize (E) /= Uint_0
-           and then Present (Esize (E));
+         return Present (Esize (E)) and then Esize (E) /= Uint_0;
       end if;
    end Known_Esize;
 
index 2a5e86d929cd5976d5ff454bdf174dd39bab2c52..8bc849029820115c14ddcfdd7ef8fe6c6054e15d 100644 (file)
@@ -860,6 +860,7 @@ package body Sem_Ch13 is
 
       if Known_Alignment (Typ)
         and then not Has_Alignment_Clause (Typ)
+        and then Present (Size)
         and then Size mod (Alignment (Typ) * SSU) /= 0
       then
          Reinit_Alignment (Typ);
@@ -7125,7 +7126,7 @@ package body Sem_Ch13 is
             else
                Check_Size (Expr, U_Ent, Size, Biased);
 
-               if Size <= 0 then
+               if No (Size) or else Size <= 0 then
                   Error_Msg_N ("Object_Size must be positive", Expr);
 
                elsif Is_Scalar_Type (U_Ent) then