public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1633] [Ada] Do not create large objects for indefinite protected types
Date: Tue, 12 Jul 2022 12:26:17 +0000 (GMT)	[thread overview]
Message-ID: <20220712122617.7AD2B38AA4F6@sourceware.org> (raw)

https://gcc.gnu.org/g:570f43b823ad9013aab5abd5868b6554f4cf019c

commit r13-1633-g570f43b823ad9013aab5abd5868b6554f4cf019c
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Jun 27 15:26:34 2022 +0200

    [Ada] Do not create large objects for indefinite protected types
    
    This plugs a small loophole in the Needs_Secondary_Stack predicate for
    some protected types and record types containing protected components.
    
    gcc/ada/
    
            * sem_util.adb (Caller_Known_Size_Record): Make entry assertion
            more robust and add guard for null argument.  For protected
            types, invoke Caller_Known_Size_Record on
            Corresponding_Record_Type.
            (Needs_Secondary_Stack): Likewise.

Diff:
---
 gcc/ada/sem_util.adb | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 0e65cbf4fb7..854afdf1170 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -23305,7 +23305,7 @@ package body Sem_Util is
       ------------------------------
 
       function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
-         pragma Assert (Typ = Underlying_Type (Typ));
+         pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ));
 
          function Depends_On_Discriminant (Typ : Entity_Id) return Boolean;
          --  Called for untagged record and protected types. Return True if Typ
@@ -23342,6 +23342,14 @@ package body Sem_Util is
          end Depends_On_Discriminant;
 
       begin
+         --  This is a protected type without Corresponding_Record_Type set,
+         --  typically because expansion is disabled. The safe thing to do is
+         --  to return True, so Needs_Secondary_Stack returns False.
+
+         if No (Typ) then
+            return True;
+         end if;
+
          --  First see if we have a variant part and return False if it depends
          --  on discriminants.
 
@@ -23367,14 +23375,18 @@ package body Sem_Util is
                                 Underlying_Type (Etype (Comp));
 
                begin
-                  if Is_Record_Type (Comp_Type)
-                        or else
-                     Is_Protected_Type (Comp_Type)
-                  then
+                  if Is_Record_Type (Comp_Type) then
                      if not Caller_Known_Size_Record (Comp_Type) then
                         return False;
                      end if;
 
+                  elsif Is_Protected_Type (Comp_Type) then
+                     if not Caller_Known_Size_Record
+                              (Corresponding_Record_Type (Comp_Type))
+                     then
+                        return False;
+                     end if;
+
                   elsif Is_Array_Type (Comp_Type) then
                      if Size_Depends_On_Discriminant (Comp_Type) then
                         return False;
@@ -23478,7 +23490,7 @@ package body Sem_Util is
    begin
       --  This is a private type which is not completed yet. This can only
       --  happen in a default expression (of a formal parameter or of a
-      --  record component). Do not expand transient scope in this case.
+      --  record component). The safe thing to do is to return False.
 
       if No (Typ) then
          return False;
@@ -23533,12 +23545,17 @@ package body Sem_Util is
       elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
          return Large_Max_Size_Mutable (Typ);
 
-      --  Indefinite (discriminated) record or protected type
+      --  Indefinite (discriminated) record type
 
-      elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
+      elsif Is_Record_Type (Typ) then
          return not Caller_Known_Size_Record (Typ);
 
-      --  Unconstrained array
+      --  Indefinite (discriminated) protected type
+
+      elsif Is_Protected_Type (Typ) then
+         return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ));
+
+      --  Unconstrained array type
 
       else
          pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));


                 reply	other threads:[~2022-07-12 12:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712122617.7AD2B38AA4F6@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).