From patchwork Tue May 30 07:20:57 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: 70280 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 A6CB9383E8C6 for ; Tue, 30 May 2023 07:22:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6CB9383E8C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431349; bh=WzdnH2B0gFHBMO+0dGKdh7JXjEaxahMr0o4Kh7A5HzA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=a73tdR+aeVYxFum898x4idi7PYwjoYKjRDzVDmY6drrAkxCaFhMiolfVRY32PpgOG FieMKsr5qILDWmYESEG8X0RuOuCLYT8l3vMWbuAIOvgCH8lu1zSTYpLz7vLNibSq/2 1GI/gwj422Vtt09nzbl6Gw4LXMq7u/vo/Eml5cdo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id E3DCB3854E70 for ; Tue, 30 May 2023 07:20:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3DCB3854E70 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f6e1393f13so27223145e9.0 for ; Tue, 30 May 2023 00:20:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431258; x=1688023258; 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=WzdnH2B0gFHBMO+0dGKdh7JXjEaxahMr0o4Kh7A5HzA=; b=dMIWpeAMQWKlfOJQiDItmXXAAXc/FwS+0lBaoSPmXDzmGvWCz6MADLLi68jD3Qfqrl VkzMKryrm1ycTqAVvS1lOyXySPlMLKAT4XUmVyqqEdg9HKrMalt7jw0QgxwFIK3Zhy1J 4xJ3rD3iuv5B/ef7WIVsmyIFtTpfrpPNepvyDV/4/RDZnFoqFnRfENtVhE/fTeo2yVj7 Ci5/mPS223paPuGdQ+3Dw1Oo+X2J34ej3bKGhbHx9bRaUTGLEMj/esELKxNvy0qWRaxB EMEu5XHp9viBOw9HSASarJPt1u2GlUXv8iiHwh2HPt+p1y0ojW5OTU6WRicK9CIyTcVZ T1Fg== X-Gm-Message-State: AC+VfDysDgUGz6frpt/bSWW0qMB7fDDNWZsSgV8gthEhy/u98qdR9uEu npMoercJZIFpoPo7E9iw+ImmIPK23AUmMR/7WTXoXQ== X-Google-Smtp-Source: ACHHUZ6MUG5nOAokOYfNp/7OViEggD65kD6HsXJOLkcBOYBzDniVnAKpUW+Q92JSfezeBdn5X7/UQQ== X-Received: by 2002:a05:600c:3786:b0:3f6:5166:6da4 with SMTP id o6-20020a05600c378600b003f651666da4mr768908wmr.31.1685431258822; Tue, 30 May 2023 00:20:58 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id l6-20020a7bc446000000b003f6d564db48sm16052884wmi.4.2023.05.30.00.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:20:58 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix fallout of recent fix for missing finalization Date: Tue, 30 May 2023 09:20:57 +0200 Message-Id: <20230530072057.2500051-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: Eric Botcazou The original fix makes it possible to create transient scopes around return statements in more cases, but it overlooks that transient scopes are reused and, in particular, that they can be promoted to secondary stack management. gcc/ada/ * exp_ch7.adb (Find_Enclosing_Transient_Scope): Return the index in the scope table instead of the scope's entity. (Establish_Transient_Scope): If an enclosing scope already exists, do not set the Uses_Sec_Stack flag on it if the node to be wrapped is a return statement which requires secondary stack management. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch7.adb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index 520bb099d33..42b41e5cf6b 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -4476,10 +4476,10 @@ package body Exp_Ch7 is function Is_Package_Or_Subprogram (Id : Entity_Id) return Boolean; -- Determine whether arbitrary Id denotes a package or subprogram [body] - function Find_Enclosing_Transient_Scope return Entity_Id; + function Find_Enclosing_Transient_Scope return Int; -- Examine the scope stack looking for the nearest enclosing transient -- scope within the innermost enclosing package or subprogram. Return - -- Empty if no such scope exists. + -- its index in the table or else -1 if no such scope exists. function Find_Transient_Context (N : Node_Id) return Node_Id; -- Locate a suitable context for arbitrary node N which may need to be @@ -4605,7 +4605,7 @@ package body Exp_Ch7 is -- Find_Enclosing_Transient_Scope -- ------------------------------------ - function Find_Enclosing_Transient_Scope return Entity_Id is + function Find_Enclosing_Transient_Scope return Int is begin for Index in reverse Scope_Stack.First .. Scope_Stack.Last loop declare @@ -4620,12 +4620,12 @@ package body Exp_Ch7 is exit; elsif Scope.Is_Transient then - return Scope.Entity; + return Index; end if; end; end loop; - return Empty; + return -1; end Find_Enclosing_Transient_Scope; ---------------------------- @@ -4822,8 +4822,8 @@ package body Exp_Ch7 is -- Local variables - Trans_Id : constant Entity_Id := Find_Enclosing_Transient_Scope; - Context : Node_Id; + Trans_Idx : constant Int := Find_Enclosing_Transient_Scope; + Context : Node_Id; -- Start of processing for Establish_Transient_Scope @@ -4831,13 +4831,29 @@ package body Exp_Ch7 is -- Do not create a new transient scope if there is already an enclosing -- transient scope within the innermost enclosing package or subprogram. - if Present (Trans_Id) then + if Trans_Idx >= 0 then -- If the transient scope was requested for purposes of managing the - -- secondary stack, then the existing scope must perform this task. + -- secondary stack, then the existing scope must perform this task, + -- unless the node to be wrapped is a return statement of a function + -- that requires secondary stack management, because the function's + -- result would be reclaimed too early (see Find_Transient_Context). if Manage_Sec_Stack then - Set_Uses_Sec_Stack (Trans_Id); + declare + SE : Scope_Stack_Entry renames Scope_Stack.Table (Trans_Idx); + + begin + if Nkind (SE.Node_To_Be_Wrapped) /= N_Simple_Return_Statement + or else not + Needs_Secondary_Stack + (Etype + (Return_Applies_To + (Return_Statement_Entity (SE.Node_To_Be_Wrapped)))) + then + Set_Uses_Sec_Stack (SE.Entity); + end if; + end; end if; return;