public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-686] ada: Get rid of secondary stack for indefinite record types with size clause
@ 2024-05-20  7:50 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-20  7:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:efc7ba5f8f113565b47214d0ffdb27a6638ab8b6

commit r15-686-gefc7ba5f8f113565b47214d0ffdb27a6638ab8b6
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Fri Mar 29 13:29:54 2024 +0100

    ada: Get rid of secondary stack for indefinite record types with size clause
    
    This change eliminates the use of the secondary stack for indefinite record
    types for which a valid (object) size clause is specified.  In accordance
    with the RM, the compiler accepts (object) size clauses on such types only
    if all the components, including those of the variants of the variant part
    if any, have a size known at compile time, and only if the clauses specify
    a value that is at least as large as the largest possible size of objects
    of the types when all the variants are considered.  However, it would still
    have used the secondary stack, despite valid (object) size clauses, before
    the change, as soon as a variant part was present in the types.
    
    gcc/ada/
    
            * freeze.ads (Check_Compile_Time_Size): Remove obsolete description
            of usage for the Size_Known_At_Compile_Time flag.
            * freeze.adb (Check_Compile_Time_Size.Size_Known): In the case where
            a variant part is present, do not return False if Esize is known.
            * sem_util.adb (Needs_Secondary_Stack.Caller_Known_Size_Record): Add
            missing "Start of processing" comment.  Return true if either a size
            clause or an object size clause has been given for the first subtype
            of the type.

Diff:
---
 gcc/ada/freeze.adb   |  1 +
 gcc/ada/freeze.ads   | 11 +++++------
 gcc/ada/sem_util.adb | 12 ++++++++++++
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 26e9d01d8b20..ea6106e6455a 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -1077,6 +1077,7 @@ package body Freeze is
                     and then
                       No (Discriminant_Default_Value (First_Discriminant (T)))
                     and then not Known_RM_Size (T)
+                    and then not Known_Esize (T)
                   then
                      return False;
                   end if;
diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads
index fc0b7678fdcc..066d8f054f6f 100644
--- a/gcc/ada/freeze.ads
+++ b/gcc/ada/freeze.ads
@@ -156,17 +156,16 @@ package Freeze is
    --    RM_Size field is set to the required size, allowing for possible front
    --    end packing of an array using this type as a component type.
    --
-   --  Note: the flag Size_Known_At_Compile_Time is used to determine if the
-   --  secondary stack must be used to return a value of the type, and also
-   --  to determine whether a component clause is allowed for a component
-   --  of the given type.
-   --
-   --  Note: this is public because of one dubious use in Sem_Res???
+   --  Note: the flag Size_Known_At_Compile_Time is used to determine whether a
+   --  size clause is allowed for the type, and also whether a component clause
+   --  is allowed for a component of the type.
    --
    --  Note: Check_Compile_Time_Size does not test the case of the size being
    --  known because a size clause is specifically given. That is because we
    --  do not allow a size clause if the size would not otherwise be known at
    --  compile time in any case.
+   --
+   --  ??? This is public because of dubious uses in Sem_Ch3 and Sem_Res
 
    procedure Check_Inherited_Conditions
     (R               : Entity_Id;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 09358278210e..15994b4d1e9c 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -22409,6 +22409,8 @@ package body Sem_Util is
             return False;
          end Depends_On_Discriminant;
 
+      --  Start of processing for Caller_Known_Size_Record
+
       begin
          --  This is a protected type without Corresponding_Record_Type set,
          --  typically because expansion is disabled. The safe thing to do is
@@ -22418,6 +22420,16 @@ package body Sem_Util is
             return True;
          end if;
 
+         --  If either size is specified for the type, then it's known in the
+         --  caller in particular. Note that, even if the clause is confirming,
+         --  this does not change the outcome since the size was already known.
+
+         if Has_Size_Clause (First_Subtype (Typ))
+           or else Has_Object_Size_Clause (First_Subtype (Typ))
+         then
+            return True;
+         end if;
+
          --  First see if we have a variant part and return False if it depends
          --  on discriminants.

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

only message in thread, other threads:[~2024-05-20  7:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-20  7:50 [gcc r15-686] ada: Get rid of secondary stack for indefinite record types with size clause Marc Poulhi?s

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).