From patchwork Tue Nov 21 10:00:56 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: 80450 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 3F6533857B80 for ; Tue, 21 Nov 2023 10:03:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 404463857C71 for ; Tue, 21 Nov 2023 10:00:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 404463857C71 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 404463857C71 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700560867; cv=none; b=wtYGnMkYbyegwiV+h4NkDI6S8FWFtPINmtppiOjU9qGKJrgzC8v0dIX4Ifo6HORgqOdaWzOLbHTU14npZ7KkbeYKYkFagQJlJEqHcuYsKI+UlKPtaRW3bkI81Mn2NLYK4e/p5XAiX0tCjimYpmRlbz5/nDpLhzwNGYWZc+VZ+Qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700560867; c=relaxed/simple; bh=O9hAGiGMuESmdJTzTRKPtds5AELAm43NN2aBcIQNwm0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=g0GMGelaUixU4eiVmQxWcJRfQ9lu2M0sFppV/yIr5ap43mMS8APDD4TuC0Xpwnh7I0H33+8HIJUzKjYUqYjfnZLm4Mz9wpwIBmSXrxlE8Z5lkF8GO775h7jdbNCnJNpCW7h+/eFx1s//S0B6NXhOg3yanEoK1k0Sl11ejiEa3Gg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c5b7764016so64895871fa.1 for ; Tue, 21 Nov 2023 02:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700560858; x=1701165658; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=I7FgsdVa/bP6x3VTB2sdghxfCpP2MbWIiizeV1lTK0o=; b=V7yg0T63Oyg0bjCnf5wj+sH/pnf6kNPHRoLToPaf1RnsfjRXOdDnX4j6itO00zSKl4 GR1LZ146Psnr9XXXYquBbVt9Xr95qNwDhVy0mGFGtlKyL61V2AWQq+pWPH2850Vb0VnE UnoYSPJBTNbhYHdbn9qz1EeeoiuwsChQDDk83lQ2bo+PzmwX+RBEL6cTpohC0rYYEYEO TGAroR7DJKMKiiZaDGu0l71xNsp1umzHNa3K3yUwuk2GgjFPMxu3eSncomVFaXB50lFc 96lkvu+rRt1WzsHHjXgquPGGxiS59P/nsYpsWCYv2eMIbfXEWydeNhCZMGKmFkfBH4sh TYLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700560858; x=1701165658; 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=I7FgsdVa/bP6x3VTB2sdghxfCpP2MbWIiizeV1lTK0o=; b=l+nHUnzFdOCklpwDzvTFA3rnJlhW/nNsPmn13hMvR3V6fVOxcZFkx9EQlhytCVQarm b/iTg4ArmQ/g52uQNodmygX5X892gRaGAsE645B3UyZPXdaEa7rB40IZk4KRN9x4YQrr mQrZiZrjr0KWuvzAVWj3PFEOcpIIMXkM1LzvbQLa0Tur5Bj7lcI+TSrxWGI4a/1IkVev vaiQ12eJvMmHHIa+PuORNoR+LxEDuXUyuDFRdj9dqaeUuTUAhAMQ8QCHy04qDohbwE9A UT6JFOfXjbPsXe26l227hZfdKRvU7v6de85+hLLlZYL3GOzZ/FpXO8xkD34MsF0h/aO5 iauw== X-Gm-Message-State: AOJu0YwarKHo7WkvpYNteELh1f4R+7HPWJOF47b92DI8c7/3VbBqtpH+ WSmdrlHQbcuGSWXUiy869lySkYsSh4fJFzwVhjOxjg== X-Google-Smtp-Source: AGHT+IGdVqJWr2wIOIwld/t45l0S8IJN4I5BEpR5mT1Qd41Pk+Ug2DMLrf62BIKUP2rchzhgqj5bnw== X-Received: by 2002:a2e:8716:0:b0:2c5:18ed:1809 with SMTP id m22-20020a2e8716000000b002c518ed1809mr6954176lji.34.1700560857748; Tue, 21 Nov 2023 02:00:57 -0800 (PST) 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 f6-20020a7bc8c6000000b004030e8ff964sm20339825wml.34.2023.11.21.02.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:00:57 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Another couple of cleanups in the finalization machinery Date: Tue, 21 Nov 2023 11:00:56 +0100 Message-ID: <20231121100056.1965191-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou For package specs and bodies that need finalizers, Build_Finalizer is invoked from the Standard scope so it needs to adjust the scope stack before creating new objects; this changes it to do so only once. For other kinds of scopes, it is invoked from Expand_Cleanup_Actions, which assumes that the correct scope is already on the stack; that's why Cleanup_Scopes adjusts the scope stack explicitly, but it should use Pop_Scope instead of End_Scope to do it. gcc/ada/ * exp_ch7.adb (Build_Finalizer): For package specs and bodies, push and pop the specs onto the scope stack only once. * inline.adb (Cleanup_Scopes): Call Pop_Scope instead of End_Scope. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch7.adb | 29 +++++++++++++---------------- gcc/ada/inline.adb | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index ef3b5c95d64..f8c12b73e9b 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -1575,19 +1575,10 @@ package body Exp_Ch7 is Prepend_To (Decls, Counter_Typ_Decl); -- The counter and its associated type must be manually analyzed - -- since N has already been analyzed. Use the scope of the spec - -- when inserting in a package. + -- since N has already been analyzed. - if For_Package then - Push_Scope (Spec_Id); - Analyze (Counter_Typ_Decl); - Analyze (Counter_Decl); - Pop_Scope; - - else - Analyze (Counter_Typ_Decl); - Analyze (Counter_Decl); - end if; + Analyze (Counter_Typ_Decl); + Analyze (Counter_Decl); Jump_Alts := New_List; end if; @@ -1933,12 +1924,8 @@ package body Exp_Ch7 is Append_To (Decls, Fin_Body); end if; - -- Push the name of the package - - Push_Scope (Spec_Id); Analyze (Fin_Spec); Analyze (Fin_Body); - Pop_Scope; -- Non-package case @@ -3419,6 +3406,10 @@ package body Exp_Ch7 is -- Step 2: Object [pre]processing if For_Package then + -- For package specs and bodies, we are invoked from the Standard + -- scope, so we need to push the specs onto the scope stack first. + + Push_Scope (Spec_Id); -- Preprocess the visible declarations now in order to obtain the -- correct number of controlled object by the time the private @@ -3496,6 +3487,12 @@ package body Exp_Ch7 is if Acts_As_Clean or Has_Ctrl_Objs or Has_Tagged_Types then Create_Finalizer; end if; + + -- Pop the scope that was pushed above for package specs and bodies + + if For_Package then + Pop_Scope; + end if; end Build_Finalizer; -------------------------- diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb index 5fff88144b2..1fbbe6d32c2 100644 --- a/gcc/ada/inline.adb +++ b/gcc/ada/inline.adb @@ -2908,7 +2908,7 @@ package body Inline is else Push_Scope (Scop); Expand_Cleanup_Actions (Decl); - End_Scope; + Pop_Scope; end if; Next_Elmt (Elmt);