public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Justin Squirek <squirek@adacore.com>
Subject: [Ada] Crash on object of protected type with defaulted access component
Date: Wed, 20 Oct 2021 19:27:47 +0000	[thread overview]
Message-ID: <20211020192747.GA3154238@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

This patch corrects issues in the compiler whereby default initializing
a protected type component of an access type containing controlled parts
with an allocator causes a crash at compile-time at the point of an
object declaration of such protected type.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_ch7.adb (Make_Final_Call): Detect expanded protected types
	and use original protected type in order to calculate
	appropriate finalization routine.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2195 bytes --]

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -8953,11 +8953,12 @@ package body Exp_Ch7 is
       Typ       : Entity_Id;
       Skip_Self : Boolean := False) return Node_Id
    is
-      Loc    : constant Source_Ptr := Sloc (Obj_Ref);
-      Atyp   : Entity_Id;
-      Fin_Id : Entity_Id := Empty;
-      Ref    : Node_Id;
-      Utyp   : Entity_Id;
+      Loc      : constant Source_Ptr := Sloc (Obj_Ref);
+      Atyp     : Entity_Id;
+      Prot_Typ : Entity_Id := Empty;
+      Fin_Id   : Entity_Id := Empty;
+      Ref      : Node_Id;
+      Utyp     : Entity_Id;
 
    begin
       Ref := Obj_Ref;
@@ -9035,6 +9036,19 @@ package body Exp_Ch7 is
          Set_Assignment_OK (Ref);
       end if;
 
+      --  Detect if Typ is a protected type or an expanded protected type and
+      --  store the relevant type within Prot_Typ for later processing.
+
+      if Is_Protected_Type (Typ) then
+         Prot_Typ := Typ;
+
+      elsif Ekind (Typ) = E_Record_Type
+        and then Present (Corresponding_Concurrent_Type (Typ))
+        and then Is_Protected_Type (Corresponding_Concurrent_Type (Typ))
+      then
+         Prot_Typ := Corresponding_Concurrent_Type (Typ);
+      end if;
+
       --  The underlying type may not be present due to a missing full view. In
       --  this case freezing did not take place and there is no [Deep_]Finalize
       --  primitive to call.
@@ -9080,7 +9094,7 @@ package body Exp_Ch7 is
       --  Protected types: these also require finalization even though they
       --  are not marked controlled explicitly.
 
-      elsif Is_Protected_Type (Typ) then
+      elsif Present (Prot_Typ) then
          --  Protected objects do not need to be finalized on restricted
          --  runtimes.
 
@@ -9090,7 +9104,7 @@ package body Exp_Ch7 is
          --  ??? Only handle the simple case for now. Will not support a record
          --  or array containing protected objects.
 
-         elsif Is_Simple_Protected_Type (Typ) then
+         elsif Is_Simple_Protected_Type (Prot_Typ) then
             Fin_Id := RTE (RE_Finalize_Protection);
          else
             raise Program_Error;



                 reply	other threads:[~2021-10-20 19:27 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=20211020192747.GA3154238@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=squirek@adacore.com \
    /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).