From patchwork Mon May 22 08:51:47 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: 97214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1310158vqo; Mon, 22 May 2023 02:15:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xEquGDQZYakNksTknnXYHRWJ0R6ZpUYKh6UszPJCMQGwA0N9O/bkJA/jqm/aRVHSxo5Ct X-Received: by 2002:a17:907:9955:b0:947:ebd5:c798 with SMTP id kl21-20020a170907995500b00947ebd5c798mr7814575ejc.54.1684746909698; Mon, 22 May 2023 02:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684746909; cv=none; d=google.com; s=arc-20160816; b=zEDChbxtEbsTmvXq/HpFjNtwplq1POCV3WU+F/lLtTy2ytFE/QEl5xQ5yEPB7bdoIa Z70ZkpmYp/Nyz7z6DbVOkO0WDUuq/7n+cjV7ZYfzcLHZLE6I6MwgidD8ZmqXjQfFp5kp uWtW4ggjcHwl0Y/fsr+un8EIY2rtcA6KM65ViLtm1S6yiMbr0msHrARzpvKuqE2RTQmA fh14IcrY1BjDkIFLwYOgvGnY4yV2aU4lL2iygTxXHw7Lg8vH8xbUqenZE70qGzLbwAvc iDlsY1ofro6aGXFp5O46fhzCdkMl5ORP3SZ1Sf4PCHjN8DZIcPfpE0KCEVxwoq+DnYio XItA== 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=ARJkfRopTH/CfzpRkQRok+qszk6YU6fYwC1KUwmbefE=; b=RU+RLJulaNTmy+dwEvj/2k9qahMVekym7hDjbEfd/GYS7/7Hc6IAhIr0DQJxqmAGBZ 6L1MRXYC/JAFLNTyZYELzv8k3PMnWoO1EAFW0Oo9JnQKpkdGxTTmLjEmIKYA93JMCCaJ 2oLimU1zSKYGpbFdJTHRu/dS/g4FtNuIp+QoFpxzGBTR0qLmE4+Lob00KVeC0KpT8RUB 0Bis9Qof3QkemQzmsxxSxbtxzKxMt7cJUE6I5FN8KCg3Y69/+UAynuScp1LgltHOYcKC ft5jpvJkcO0C1wbqIjOSg9o5Nwph3yE20XXJAWUgluaiEd0oprb8M4WBjyzbPiunhSgC J0xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="wN/XcHZN"; 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 n17-20020a17090673d100b00965fc6a72f7si4200665ejl.679.2023.05.22.02.15.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 02:15:09 -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="wN/XcHZN"; 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 7B8203830331 for ; Mon, 22 May 2023 09:03:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B8203830331 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684746216; bh=ARJkfRopTH/CfzpRkQRok+qszk6YU6fYwC1KUwmbefE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=wN/XcHZNbAm7iALwWc26Rt5gVxK4Bz1URxW62H/aw66KE7XY8CxriuWzwg2cjiGAn 2naVVYRQW/DD87NFveyZNwoN+j2yK0CP7DNRx5yCb97JIvi9Xh1E1wwKvg1g8sYI/6 eC5XAIgOv7jQgv2sVxnuurRCPt4n/ojhvYlhxt2s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id B501F3882111 for ; Mon, 22 May 2023 08:51:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B501F3882111 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-30796c0cbcaso5756530f8f.1 for ; Mon, 22 May 2023 01:51:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684745509; x=1687337509; 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=ARJkfRopTH/CfzpRkQRok+qszk6YU6fYwC1KUwmbefE=; b=NaitSOiBNEtEQ7JM2x18t9WZVLqkd53/G3Cac9/X+RDLllaK8x7z6RckgSXn0M18ID qH9ds63ZwiMYnUh1e7t33faLpYgDURwcf+2js/ihskkmRB4suNSmWzDtsWIFhPOZxyWv f5MY1rQUc1IT4ebUZom77ZEcCXVNC8XlmlBimzx7TMeud4ITjfvCxeWccehICRtHDmt8 xOIFPbYXuODGJ6pJIMof7tTZsylVew9Km1OeZjtUTMN6bg49qWsr4TYQpg5+8tdgD3Yt yyEm9enn9Y7z7Dd5i6pSN9n8NRl6nBLP2m16oumpMY8po3sebEjmC4KkExtLu5pVdZdD dIBw== X-Gm-Message-State: AC+VfDzULXRbSwqitjsdbvvjX5clFlR0HWwmwqpQh84Fbs08o1/dgvWz tPY8gbfvcQe3PagUKA2F7K5qi6txPnOgESSh6rzhbw== X-Received: by 2002:a5d:4fce:0:b0:2f5:d3d7:7af4 with SMTP id h14-20020a5d4fce000000b002f5d3d77af4mr6938611wrw.63.1684745509617; Mon, 22 May 2023 01:51:49 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id w16-20020a5d5450000000b00306415ac69asm6996236wrv.15.2023.05.22.01.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 01:51:49 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Small cleanup in support for protected subprograms Date: Mon, 22 May 2023 10:51:47 +0200 Message-Id: <20230522085147.1727570-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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?1766585175186752192?= X-GMAIL-MSGID: =?utf-8?q?1766585175186752192?= From: Eric Botcazou This moves the propagation of the Uses_Sec_Stack flag, from the original to the rewritten subprogram, to the point where the latter is expanded, along with the propagation of the Has_Nested_Subprogram flag, as well as addresses a ??? comment in the same block of code. No functional changes. gcc/ada/ * inline.adb (Cleanup_Scopes): Do not propagate the Uses_Sec_Stack flag from original to rewritten protected subprograms here... * exp_ch9.adb (Expand_N_Protected_Body) : ...but here instead. Add local variables and remove a useless test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch9.adb | 97 +++++++++++++++++++++++---------------------- gcc/ada/inline.adb | 11 ----- 2 files changed, 49 insertions(+), 59 deletions(-) diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 50b9d072d84..b51c60ea506 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -8393,9 +8393,11 @@ package body Exp_Ch9 is Current_Node : Node_Id; Disp_Op_Body : Node_Id; New_Op_Body : Node_Id; + New_Op_Spec : Node_Id; Op_Body : Node_Id; Op_Decl : Node_Id; Op_Id : Entity_Id; + Op_Spec : Entity_Id; function Build_Dispatching_Subprogram_Body (N : Node_Id; @@ -8512,11 +8514,12 @@ package body Exp_Ch9 is null; when N_Subprogram_Body => + Op_Spec := Corresponding_Spec (Op_Body); -- Do not create bodies for eliminated operations if not Is_Eliminated (Defining_Entity (Op_Body)) - and then not Is_Eliminated (Corresponding_Spec (Op_Body)) + and then not Is_Eliminated (Op_Spec) then if Lock_Free_Active then New_Op_Body := @@ -8531,7 +8534,9 @@ package body Exp_Ch9 is Current_Node := New_Op_Body; Analyze (New_Op_Body); - -- When the original protected body has nested subprograms, + New_Op_Spec := Corresponding_Spec (New_Op_Body); + + -- When the original subprogram body has nested subprograms, -- the new body also has them, so set the flag accordingly -- and reset the scopes of the top-level nested subprograms -- and other declaration entities so that they now refer to @@ -8541,58 +8546,54 @@ package body Exp_Ch9 is -- subprogram entity isn't available via Corresponding_Spec -- until after the above Analyze call.) - if Has_Nested_Subprogram (Corresponding_Spec (Op_Body)) then - Set_Has_Nested_Subprogram - (Corresponding_Spec (New_Op_Body)); - - Reset_Scopes_To - (New_Op_Body, Corresponding_Spec (New_Op_Body)); + if Has_Nested_Subprogram (Op_Spec) then + Set_Has_Nested_Subprogram (New_Op_Spec); + Reset_Scopes_To (New_Op_Body, New_Op_Spec); end if; + -- Similarly, when the original subprogram body uses the + -- secondary stack, the new body also does. This is needed + -- when the cleanup actions of the subprogram are delayed + -- because it contains a package instance with a body. + + Set_Uses_Sec_Stack (New_Op_Spec, Uses_Sec_Stack (Op_Spec)); + -- Build the corresponding protected operation. This is -- needed only if this is a public or private operation of -- the type. - -- Why do we need to test for Corresponding_Spec being - -- present here when it's assumed to be set further above - -- in the Is_Eliminated test??? - - if Present (Corresponding_Spec (Op_Body)) then - Op_Decl := - Unit_Declaration_Node (Corresponding_Spec (Op_Body)); - - if Nkind (Parent (Op_Decl)) = N_Protected_Definition then - if Lock_Free_Active then - New_Op_Body := - Build_Lock_Free_Protected_Subprogram_Body - (Op_Body, Pid, Specification (New_Op_Body)); - else - New_Op_Body := - Build_Protected_Subprogram_Body ( - Op_Body, Pid, Specification (New_Op_Body)); - end if; - - Insert_After (Current_Node, New_Op_Body); - Analyze (New_Op_Body); - Current_Node := New_Op_Body; - - -- Generate an overriding primitive operation body for - -- this subprogram if the protected type implements - -- an interface. - - if Ada_Version >= Ada_2005 - and then Present (Interfaces ( - Corresponding_Record_Type (Pid))) - then - Disp_Op_Body := - Build_Dispatching_Subprogram_Body ( - Op_Body, Pid, New_Op_Body); - - Insert_After (Current_Node, Disp_Op_Body); - Analyze (Disp_Op_Body); - - Current_Node := Disp_Op_Body; - end if; + Op_Decl := Unit_Declaration_Node (Op_Spec); + + if Nkind (Parent (Op_Decl)) = N_Protected_Definition then + if Lock_Free_Active then + New_Op_Body := + Build_Lock_Free_Protected_Subprogram_Body + (Op_Body, Pid, Specification (New_Op_Body)); + else + New_Op_Body := + Build_Protected_Subprogram_Body + (Op_Body, Pid, Specification (New_Op_Body)); + end if; + + Insert_After (Current_Node, New_Op_Body); + Current_Node := New_Op_Body; + Analyze (New_Op_Body); + + -- Generate an overriding primitive operation body for + -- this subprogram if the protected type implements + -- an interface. + + if Ada_Version >= Ada_2005 + and then + Present (Interfaces (Corresponding_Record_Type (Pid))) + then + Disp_Op_Body := + Build_Dispatching_Subprogram_Body ( + Op_Body, Pid, New_Op_Body); + + Insert_After (Current_Node, Disp_Op_Body); + Current_Node := Disp_Op_Body; + Analyze (Disp_Op_Body); end if; end if; end if; diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index c3911cf70e8..07f806a40de 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -2831,17 +2831,6 @@ package body Inline is and then Is_Protected_Type (Underlying_Type (Scope (Scop))) and then Present (Protected_Body_Subprogram (Scop)) then - -- If a protected operation contains an instance, its cleanup - -- operations have been delayed, and the subprogram has been - -- rewritten in the expansion of the enclosing protected body. It - -- is the corresponding subprogram that may require the cleanup - -- operations, so propagate the information that triggers cleanup - -- activity. - - Set_Uses_Sec_Stack - (Protected_Body_Subprogram (Scop), - Uses_Sec_Stack (Scop)); - Scop := Protected_Body_Subprogram (Scop); end if;