From patchwork Fri May 26 07:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 70128 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 732FD394880A for ; Fri, 26 May 2023 07:39:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 732FD394880A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086797; bh=000nN56qnuHRjwfTxC/97k9RcFtYD9vaRqtnl8vUv44=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Yqm0ibpXC/5BRpA9fg/AOTIpyKHMV6w3S3PAQ7Z90iiW/RKhvTdPCZenfYcWTLDUp 8vI/xwknrZKdWyJtLgGA3qXhKERGOd9+QNTl7woWLWZnsTCSX5tRtPz710wWFw7uma 3A/QyO3wCFTjJY5GRORSFFjM0hDJNj7AOTCaBTxY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 12DD63852771 for ; Fri, 26 May 2023 07:36:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12DD63852771 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3078a3f3b5fso349427f8f.0 for ; Fri, 26 May 2023 00:36:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086568; x=1687678568; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=000nN56qnuHRjwfTxC/97k9RcFtYD9vaRqtnl8vUv44=; b=IgX4G/0K11gC0FUozWzTE/nEk+MckY9gNsrLBG8BrJH3NROxbdRkHPJEBKawpjjXHG Olz0MRRtZl0vBWaZ00hE7/2l9ozOd2uXbm3CSJ0SAFG0SvUUVntY3iAbSAcpTGxHQhZy +lxjdangpkXtR110zo+u9Bhx2cYHPj4O1UJHC5aUtO1LYZY7cIN7wn/vZrmeSgnokAup I7doEcDE3uoOtytp5S5idE6y0aq81hirhche96NTKba4KG6bQs+q3zpizf/TRfELUItX +03fv44AN/ymQScSgsl7K6PY9O/cZQY3PtPNL4A0QZ+OSKyBWwZeaP2KUYawO2WcDklG UMKA== X-Gm-Message-State: AC+VfDx2RKkje/ZRO1zyWklRrnCVDhBoBXPHmtc2faXjDR5loLuEsDIM gZ2XunWpZ4Gj14YDNYSvRFwIDfXMTxP4YC9AtGqvmQ== X-Google-Smtp-Source: ACHHUZ40VNrS0qowdOQmq4D9AwKplPMHNCXz08Iog/OuGJ/JzAI+fl0eRvyUmKoSEXpHzUyg31AyUA== X-Received: by 2002:adf:dcc7:0:b0:2e4:6197:21b3 with SMTP id x7-20020adfdcc7000000b002e4619721b3mr647379wrm.55.1685086567793; Fri, 26 May 2023 00:36:07 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id c4-20020adfed84000000b0030795b2be15sm4136351wro.103.2023.05.26.00.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:36:07 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Duplicate declaration of _master entity Date: Fri, 26 May 2023 09:36:06 +0200 Message-Id: <20230526073606.2068512-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Javier Miranda 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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.