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: 99350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp292193vqr; Fri, 26 May 2023 00:45:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64GNG6CNTYQDxJJiGMRvVksMRC8dXdQDkOvdXWaZO1LU35F8A2vAs28DPMuG2Um1+MVqDB X-Received: by 2002:aa7:d84e:0:b0:504:a248:3741 with SMTP id f14-20020aa7d84e000000b00504a2483741mr895145eds.14.1685087115201; Fri, 26 May 2023 00:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685087115; cv=none; d=google.com; s=arc-20160816; b=G3JXoRqqHJTKgrG5VniSb2K4gz6T+RjqjMer/XI3T6sWFuO5JgaoW7SqGXKfcbRPET hDvqIdeMkYRRzqvLWkJXG/tr75LBiJU15MuqwmwDlq21SQtcfFe/3lR5svKo81RWVNNj UL41Bv1wySSCLlQoEtCjo/X4MUPbCI22NHkk3VoFYmQg947oQh7jOfk/cHc1Y/XfMh6J sK23BwSD62HxBvWHvFpYPrndvVQsuuwfj0TDPFpdYjB6lk6xHlqoz2goJTyAihpWIKwv Kl1EUq9SKLiAS16W6PkaiIYmdj+Ma/2kqGO+9nnvMOXfSaB3vyotwAmjt0wpkqi65b2a Gxag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=000nN56qnuHRjwfTxC/97k9RcFtYD9vaRqtnl8vUv44=; b=svDcQvD6Ov+SHf4xD0vL1mPdhBEBjxEggpMru2Tm+kbGqS11kBd1njcu4+/IfR+Ttl 32CNdWMvWGUAnLxXnwmroDq9El4wDfhh9kpKwLQwhXaqkOdq8CLkCoTWAbEAiqzhRaZN /BuCWsHunzxMBBmROKQa0S4qvd8O2NnFekgaIsuEmdEwZPF7YXXe5yODAoy9ZKA2L7BC lm+Sa4ZOsaZXA1esw9xV71Owp+i4hMFgKj3FAth/2PHRrFVO8XHEpZNlj7T6dX1ccXQM gVz0tSuvgxY6+6ipRt4WTc/vWNVpUnlb3sRq3bHFg7hOqFHqA0xaogwRsMCbaWck4xeR xA6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IzNLis7I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r26-20020aa7cfda000000b0050dbd30820bsi2274439edy.231.2023.05.26.00.45.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:45:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IzNLis7I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09F5A3889829 for ; Fri, 26 May 2023 07:40:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09F5A3889829 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086814; 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=IzNLis7IqJOxsw5+tUXxgCXOHHkpI3qRRnrR73h8/CsVS953+RjAaK/V8tNJJ8NkH yvq8fbabwf1yQ0z7GajW7ajIxw54q13UPTOYaHi5txMvPnibWQZcqw7GDGTn/plE9U ZuPWsZQgpC+5VkjDo7oGa9rIzaaYK3f5ai4G8Uu8= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766941906933529132?= X-GMAIL-MSGID: =?utf-8?q?1766941906933529132?= 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.