public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Javier Miranda <miranda@adacore.com>
Subject: [COMMITTED] ada: Missing master of task causing assertion failure
Date: Tue,  8 Nov 2022 09:41:39 +0100	[thread overview]
Message-ID: <20221108084139.300802-1-poulhies@adacore.com> (raw)

From: Javier Miranda <miranda@adacore.com>

gcc/ada/

	* exp_ch9.adb
	(Build_Master_Entity): Handle missing case: when the context of
	the master is a BIP function whose result type has tasks.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch9.adb | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index decf61782af..70ede15901e 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -3207,10 +3207,45 @@ package body Exp_Ch9 is
          Find_Enclosing_Context (Par, Context, Context_Id, Decls);
       end if;
 
+      --  When the enclosing context is a BIP function whose result type has
+      --  tasks, the function has an extra formal that is the master of the
+      --  tasks to be created by its returned object (that is, when its
+      --  enclosing context is a return statement). However, if the body of
+      --  the function creates tasks before its return statements, such tasks
+      --  need their own master.
+
+      if Has_Master_Entity (Context_Id)
+        and then Ekind (Context_Id) = E_Function
+        and then Is_Build_In_Place_Function (Context_Id)
+        and then Needs_BIP_Task_Actuals (Context_Id)
+      then
+         --  No need to add it again if previously added
+
+         declare
+            Master_Present : Boolean;
+
+         begin
+            --  Handle transient scopes
+
+            if Context_Id /= Current_Scope then
+               Push_Scope (Context_Id);
+               Master_Present :=
+                 Present (Current_Entity_In_Scope (Name_uMaster));
+               Pop_Scope;
+            else
+               Master_Present :=
+                 Present (Current_Entity_In_Scope (Name_uMaster));
+            end if;
+
+            if Master_Present then
+               return;
+            end if;
+         end;
+
       --  Nothing to do if the context already has a master; internally built
       --  finalizers don't need a master.
 
-      if Has_Master_Entity (Context_Id)
+      elsif Has_Master_Entity (Context_Id)
         or else Is_Finalizer (Context_Id)
       then
          return;
-- 
2.34.1


                 reply	other threads:[~2022-11-08  8:41 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=20221108084139.300802-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=miranda@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).