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: 70278 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 98207386BB4E for ; Tue, 30 May 2023 07:22:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98207386BB4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431333; bh=Lg4Er1XLHOv5fIW49Wj6VvrIY6uehVGCgvEQURuZLTQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oGvyuEI6U+byBkvG/caZgdBLcpKcwAMmWNcXXOSyAahabvOCbZL6l0akoUA6cY/DP 5Aeb7Oygv9+C+rucQo6DKuUARv7q5yI2xDMhO4Udv5BpKiK7+dFTbPJqi9LvAP/BiH 5hLq57cdAy/EUinaDPgridYjMlwNllSPX1Piy/Lc= 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-Google-Smtp-Source: ACHHUZ7THPOWEBAVoFKbwRV68dYK9faInwr8r8galRalvj2JFkk+K4XxaKlw4kJtQdoXTn0kT/RNCA== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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)));