public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1268] ada: Duplicate declaration of _master entity
@ 2023-05-26  7:36 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2023-05-26  7:36 UTC (permalink / raw)
  To: gcc-cvs

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

commit r14-1268-gbdda3d2960f884488cf9fcc817a541e709ddb7e7
Author: Javier Miranda <miranda@adacore.com>
Date:   Tue Mar 14 20:46:34 2023 +0000

    ada: Duplicate declaration of _master entity
    
    gcc/ada/
    
            * exp_ch9.adb (Build_Class_Wide_Master): Remember internal blocks
            that have a task master entity declaration.
            (Build_Master_Entity): Code cleanup.
            * sem_util.ads (Is_Internal_Block): New subprogram.
            * sem_util.adb (Is_Internal_Block): New subprogram.

Diff:
---
 gcc/ada/exp_ch9.adb  | 48 +++++++++++++++++++++++++-----------------------
 gcc/ada/sem_util.adb | 10 ++++++++++
 gcc/ada/sem_util.ads |  5 +++++
 3 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index e0eeec49c01..df4a083e96b 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -1219,9 +1219,9 @@ package body Exp_Ch9 is
       then
          declare
             Ins_Nod : Node_Id;
+            Par_Nod : Node_Id;
 
          begin
-            Set_Has_Master_Entity (Master_Scope);
             Master_Decl := Build_Master_Declaration (Loc);
 
             --  Ensure that the master declaration is placed before its use
@@ -1231,6 +1231,30 @@ package body Exp_Ch9 is
                Ins_Nod := Parent (Ins_Nod);
             end loop;
 
+            Par_Nod := Parent (List_Containing (Ins_Nod));
+
+            --  For internal blocks created by Wrap_Loop_Statement, Wrap_
+            --  Statements_In_Block, and Build_Abort_Undefer_Block, remember
+            --  that they have a task master entity declaration; required by
+            --  Build_Master_Entity to avoid creating another master entity,
+            --  and also ensures that subsequent calls to Find_Master_Scope
+            --  return this scope as the master scope of Typ.
+
+            if Is_Internal_Block (Par_Nod) then
+               Set_Has_Master_Entity (Entity (Identifier (Par_Nod)));
+
+            elsif Nkind (Par_Nod) = N_Handled_Sequence_Of_Statements
+              and then Is_Internal_Block (Parent (Par_Nod))
+            then
+               Set_Has_Master_Entity (Entity (Identifier (Parent (Par_Nod))));
+
+            --  Otherwise remember that this scope has an associated task
+            --  master entity declaration.
+
+            else
+               Set_Has_Master_Entity (Master_Scope);
+            end if;
+
             Insert_Before (First (List_Containing (Ins_Nod)), Master_Decl);
             Analyze (Master_Decl);
 
@@ -3169,28 +3193,6 @@ package body Exp_Ch9 is
          Par := Parent (Obj_Or_Typ);
       end if;
 
-      --  For transient scopes check if the master entity is already defined
-
-      if Is_Type (Obj_Or_Typ)
-        and then Ekind (Scope (Obj_Or_Typ)) = E_Block
-        and then Is_Internal (Scope (Obj_Or_Typ))
-      then
-         declare
-            Master_Scope : constant Entity_Id :=
-                             Find_Master_Scope (Obj_Or_Typ);
-         begin
-            if Has_Master_Entity (Master_Scope)
-              or else Is_Finalizer (Master_Scope)
-            then
-               return;
-            end if;
-
-            if Present (Current_Entity_In_Scope (Name_uMaster)) then
-               return;
-            end if;
-         end;
-      end if;
-
       --  When creating a master for a record component which is either a task
       --  or access-to-task, the enclosing record is the master scope and the
       --  proper insertion point is the component list.
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index d0e0fcd3da1..9967bd20506 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -17640,6 +17640,16 @@ package body Sem_Util is
       return False;
    end Is_Inlinable_Expression_Function;
 
+   -----------------------
+   -- Is_Internal_Block --
+   -----------------------
+
+   function Is_Internal_Block (N : Node_Id) return Boolean is
+   begin
+      return Nkind (N) = N_Block_Statement
+        and then Is_Internal (Entity (Identifier (N)));
+   end Is_Internal_Block;
+
    -----------------
    -- Is_Iterator --
    -----------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 185cf2ceabd..4333c495ae7 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2101,6 +2101,11 @@ package Sem_Util is
    --     9. Nominal subtype of the returned object statically compatible
    --        with the result subtype of the expression function.
 
+   function Is_Internal_Block (N : Node_Id) return Boolean;
+   pragma Inline (Is_Internal_Block);
+   --  Determine if N is an N_Block_Statement with an internal label. See
+   --  Add_Block_Identifier.
+
    function Is_Iterator (Typ : Entity_Id) return Boolean;
    --  AI05-0139-2: Check whether Typ is one of the predefined interfaces in
    --  Ada.Iterator_Interfaces, or it is derived from one.

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

only message in thread, other threads:[~2023-05-26  7:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26  7:36 [gcc r14-1268] ada: Duplicate declaration of _master entity 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).