From patchwork Tue May 30 07:20:34 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: 100584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1995732vqr; Tue, 30 May 2023 00:24:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7od2bOT6TH8IIUEACMSy13Pkk6sxlLBU7+yeLvQBKvpRtUtYLuUmjOwSNFG29JBquJ/O7c X-Received: by 2002:aa7:d6cb:0:b0:514:a0ec:68ad with SMTP id x11-20020aa7d6cb000000b00514a0ec68admr939283edr.24.1685431466383; Tue, 30 May 2023 00:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685431466; cv=none; d=google.com; s=arc-20160816; b=XWr1OR7zEGKEn3R2Sz+ouiHUPvOqOejR/vS74exwhv5iUdagHVoci1NT6VG9iNarx+ S9tfvypJ03hoc5fWaz60kwPM19ffkFkEZ98+4G14nIhhyleyM6nFSxSzbQdpItOi5OyB p1s5iwfGgHSoZpbsS6jOQ93AdfYhL51RCpxyaRX6mwFQVERGGwdYts+lWgMPljHWU5Ss mQMI8EG7//2gXvdEXECxQXNCx7IVr2QPfIap49GgbYVVZAbSz5hizavlPIVyXZ0/H67H 9YoZ3WbLIvAL11F8oEDpBXsvHTn80MCvMoRsaIXzvscmN26uEaJQC++n31xjnL6A1sYa zqtQ== 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=Lg4Er1XLHOv5fIW49Wj6VvrIY6uehVGCgvEQURuZLTQ=; b=kXvHbDPvJp/nIh5FT9GZ/IdxUfPABZJ33yKJ0rI+ZeW6TrdgRQ3APWnxDCb+ZuTjYW aztAHWioxz3P8MUl5g9XXXiJBo4MtyhHZutdjXuTbJrqMIwM6dfZlOz/DThXyRtJxRkl 7m41BixDtlcyvylx+gzuYTiR4CRXuzA9GNjl1P7bs3nibuAv+XVEjQxhEQRYlkj0bnK4 VkGbca2miNa6xM9HD/RUADj2fhe6ZlD5ZZG2+kFMMJ3xEL9EEAvN8I/mJq1qICA1aexu i24XhXd/qnvEjWr4MDTfjyNR3brAIX66JOgPFNJnApGJ84C63FhZuqaka4DPh0zAlzyR oKMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b4VvtWzj; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d12-20020aa7ce0c000000b0050bcc56b51esi4740127edv.283.2023.05.30.00.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:24:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b4VvtWzj; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 1E88D38715AE for ; Tue, 30 May 2023 07:22:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E88D38715AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431350; bh=Lg4Er1XLHOv5fIW49Wj6VvrIY6uehVGCgvEQURuZLTQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=b4VvtWzj4ru91Nq8Z3y7TnfDJzM5cX2c8RkXXN8vKXGHZh+m3h0otbA/BfoKVQqzK QnloHrw+qg5tBnzlqBwNIDU0dUvNHkXTF6NpaDSBmp/Rd3S1/cqjR60vuDNgAn66ME W9jjTeURvpoIBFKciOJGewzv7XINGYXM9LJilcB8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id DCEAB3856275 for ; Tue, 30 May 2023 07:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCEAB3856275 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f6dfc4dffaso27614985e9.0 for ; Tue, 30 May 2023 00:20:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431235; x=1688023235; 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=Lg4Er1XLHOv5fIW49Wj6VvrIY6uehVGCgvEQURuZLTQ=; b=lHWEuIg72juMzTLs0+A14mOaYpYgYpOQyv9DJQxbD+nWIj5IhEfs4zlG0hfatIHka0 dGvFOnNdpPHmRKcNo/2jeLciy0zQJ2vtTAHdgaB/jTLG8jrBhS7gq7sSoZKCYrg5S/+Q cVyHKLvHR+cB2HXL9oipdeE+0RysuHwGumPhLWFDfRTx64LMuw0KQEMT+dgodaRRE5MQ BVImuYSLbCkwr7t4bkRuc83EWBWWz8PiFwBUAFx2UoP+h10bGijU7sbfvK3PZm0u8mvk 5Y+2I2h6s/VKYEUbFBU5CTvGg86bxYtWk+uYragY7hTHrkyDnShiu0uEJETPJObEeJe/ Jqmg== X-Gm-Message-State: AC+VfDzLnMuKJUOEKPBFfAPcWQEdhO2I4CR3lCIX3EWRj6l8SmVfW5U8 qXQU1H2pF7wzsM/moPya+ExTGIWFLK+Oat9uYa39PQ== X-Received: by 2002:a7b:cc8d:0:b0:3f7:5e3:c1f2 with SMTP id p13-20020a7bcc8d000000b003f705e3c1f2mr878684wma.8.1685431235692; Tue, 30 May 2023 00:20:35 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id f13-20020a7bcd0d000000b003f60d0eef36sm20105273wmj.48.2023.05.30.00.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:20:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix regression of secondary stack management in return statements Date: Tue, 30 May 2023 09:20:34 +0200 Message-Id: <20230530072034.2499684-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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?1767302985069491280?= X-GMAIL-MSGID: =?utf-8?q?1767302985069491280?= From: Eric Botcazou This happens when the expression of the return statement is a call that does not return on the same stack as the enclosing function. gcc/ada/ * sem_res.adb (Resolve_Call): Restrict previous change to calls that return on the same stack as the enclosing function. Tidy up. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_res.adb | 69 ++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index b16e48917f2..c2a4bcb58cd 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -6923,69 +6923,62 @@ package body Sem_Res is return; end if; - -- Create a transient scope if the resulting type requires it + -- Create a transient scope if the expander is active and the resulting + -- type requires it. -- There are several notable exceptions: - -- a) In init procs, the transient scope overhead is not needed, and is - -- even incorrect when the call is a nested initialization call for a - -- component whose expansion may generate adjust calls. However, if the - -- call is some other procedure call within an initialization procedure - -- (for example a call to Create_Task in the init_proc of the task - -- run-time record) a transient scope must be created around this call. - - -- b) Enumeration literal pseudo-calls need no transient scope - - -- c) Intrinsic subprograms (Unchecked_Conversion and source info + -- a) Intrinsic subprograms (Unchecked_Conversion and source info -- functions) do not use the secondary stack even though the return -- type may be unconstrained. - -- d) Calls to a build-in-place function, since such functions may + -- b) Subprograms that are ignored ghost entities do not return anything + + -- c) Calls to a build-in-place function, since such functions may -- allocate their result directly in a target object, and cases where -- the result does get allocated in the secondary stack are checked for -- within the specialized Exp_Ch6 procedures for expanding those -- build-in-place calls. - -- e) Calls to inlinable expression functions do not use the secondary + -- d) Calls to inlinable expression functions do not use the secondary -- stack (since the call will be replaced by its returned object). - -- f) If the subprogram is marked Inline_Always, then even if it returns + -- e) If the subprogram is marked Inline, then even if it returns -- an unconstrained type the call does not require use of the secondary -- stack. However, inlining will only take place if the body to inline -- is already present. It may not be available if e.g. the subprogram is -- declared in a child instance. - -- g) If the subprogram is a static expression function and the call is + -- f) If the subprogram is a static expression function and the call is -- a static call (the actuals are all static expressions), then we never -- want to create a transient scope (this could occur in the case of a -- static string-returning call). - -- h) If the subprogram is an ignored ghost entity, because it does not - -- return anything. - - -- i) If the call is the expression of a simple return statement, since - -- it will be handled as a tail call by Expand_Simple_Function_Return. - - if Is_Inlined (Nam) - and then Has_Pragma_Inline (Nam) - and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration - and then Present (Body_To_Inline (Unit_Declaration_Node (Nam))) - then - null; + -- g) If the call is the expression of a simple return statement that + -- returns on the same stack, since it will be handled as a tail call + -- by Expand_Simple_Function_Return. - elsif Ekind (Nam) = E_Enumeration_Literal - or else Is_Build_In_Place_Function (Nam) - or else Is_Intrinsic_Subprogram (Nam) - or else Is_Inlinable_Expression_Function (Nam) - or else Is_Static_Function_Call (N) - or else Is_Ignored_Ghost_Entity (Nam) - or else Nkind (Parent (N)) = N_Simple_Return_Statement - then - null; - - elsif Expander_Active + if Expander_Active and then Ekind (Nam) in E_Function | E_Subprogram_Type and then Requires_Transient_Scope (Etype (Nam)) + and then not Is_Intrinsic_Subprogram (Nam) + and then not Is_Ignored_Ghost_Entity (Nam) + and then not Is_Build_In_Place_Function (Nam) + and then not Is_Inlinable_Expression_Function (Nam) + and then not (Is_Inlined (Nam) + and then Has_Pragma_Inline (Nam) + and then Nkind (Unit_Declaration_Node (Nam)) = + N_Subprogram_Declaration + and then + Present (Body_To_Inline (Unit_Declaration_Node (Nam)))) + and then not Is_Static_Function_Call (N) + and then not (Nkind (Parent (N)) = N_Simple_Return_Statement + and then + Needs_Secondary_Stack + (Etype + (Return_Applies_To + (Return_Statement_Entity (Parent (N))))) = + Needs_Secondary_Stack (Etype (Nam))) then Establish_Transient_Scope (N, Needs_Secondary_Stack (Etype (Nam)));