* [Ada] Fix infinite loop in compilation of illegal code
@ 2021-09-22 15:15 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-09-22 15:15 UTC (permalink / raw)
To: gcc-patches; +Cc: Yannick Moy
[-- Attachment #1: Type: text/plain, Size: 658 bytes --]
When rewriting a derived type declaration into a subtype declaration,
the aspect specifications were shared in a way that made the aspect
point to a node outside of the tree as parent node. This could lead to
an infinite loop on illegal code using a non-static value for attribute
Object_Size of the type.
Tested on x86_64-pc-linux-gnu, committed on trunk
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2628 bytes --]
diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb
--- 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
--- 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
--- 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
--- 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-22 15:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 15:15 [Ada] Fix infinite loop in compilation of illegal code Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).