From: Yannick Moy Date: Tue, 20 Jul 2021 11:59:19 +0000 (+0200) Subject: [Ada] Fix infinite loop in compilation of illegal code X-Git-Tag: basepoints/gcc-13~4505 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c61547d80c8b4c611284b63e92d10f87c9898b2;p=thirdparty%2Fgcc.git [Ada] Fix infinite loop in compilation of illegal code 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. --- diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index 540d4ff74af3..d69d4037ebce 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -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; diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads index 6fb5aa6c2b6f..94e589e70ac6 100644 --- a/gcc/ada/atree.ads +++ b/gcc/ada/atree.ads @@ -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 diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb index 15bd9e885b27..cbd957bd9b99 100644 --- a/gcc/ada/einfo-utils.adb +++ b/gcc/ada/einfo-utils.adb @@ -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; diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 2a5e86d929cd..8bc849029820 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -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