public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3808] [Ada] Fix infinite loop in compilation of illegal code
@ 2021-09-22 15:11 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-09-22 15:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8c61547d80c8b4c611284b63e92d10f87c9898b2

commit r12-3808-g8c61547d80c8b4c611284b63e92d10f87c9898b2
Author: Yannick Moy <moy@adacore.com>
Date:   Tue Jul 20 13:59:19 2021 +0200

    [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:
---
 gcc/ada/atree.adb       | 10 ++++++++--
 gcc/ada/atree.ads       |  1 +
 gcc/ada/einfo-utils.adb |  3 +--
 gcc/ada/sem_ch13.adb    |  3 ++-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb
index 540d4ff74af..d69d4037ebc 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 6fb5aa6c2b6..94e589e70ac 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 15bd9e885b2..cbd957bd9b9 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 2a5e86d929c..8bc84902982 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-22 15:11 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:11 [gcc r12-3808] [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).