From patchwork Tue May 23 08:09:25 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: 97876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1979345vqo; Tue, 23 May 2023 01:24:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50rgKeXB1xlQF5GHKAIeOZ5m0emBOzWzVZzaXHKSIDfUYNAtwLFLQwL5lU0u/B5/acSEeA X-Received: by 2002:aa7:cd62:0:b0:510:daee:46d8 with SMTP id ca2-20020aa7cd62000000b00510daee46d8mr10577288edb.5.1684830284117; Tue, 23 May 2023 01:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684830284; cv=none; d=google.com; s=arc-20160816; b=Z7q82+BUf9BcycwR/IK8omLehkKwGJCw0QBn+UAFHx88gjnX4gyCS6MmmZlhOB9K4c k9bB0tlknfDnRZqmrB9Hmxjogq0zkBOpns2d9BuzrzKsxhBgjcFYThXE1RacJW0o+SD+ Jgfo7CcoIoLAWW3Qwm7r7Bc28nDXWnYTL5J0u8QdBtHuzrGpDW6EhY/sxZlOcdwYLvtI yOf3hBo3QYcwt83KMhSt1ArebqSIOtj4eUaMnlRj20pVGeEsOoz7AWfOewFO3sV/tQdJ HKczx4kBuTN0mT5aDBRDRnookdCllzF5Pbyoyutk3vEv7tA0aLZbAbol90VhFypsSVte 9meQ== 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=jZC0mwqXK+612+IaLLu4cl99LIQVPYLb9vOCZyE6yPo=; b=lHRcyMd7dg2rGFVieETtxSAioHfkTuw79RkT/4U09undSsjM3kpNr6oU856zMC3BHF ptkJnxyxciqmavpw0IBKoY6LbBBQ5CkMAbyfJEVzP/ysGnUchfMrx2aWVkWTL+ZXLHOp FQG1K+XLYx+e2y0c1HiPXpV3nNviPGxR5vjr24J7mrZhJloMenEF7Q7ZnSsdQLlfeauf fraMZ5JfznyfgTZSy7/yYUpiGWNtwDagWDUvelTzk7nglVmYGieYSGQPp9Y8rALF158M 0BJmpIViIr64rj7unSZZVRp+kak2coWiU1uEczMyhqcIU+x1Ix4VoUgWlyxZ+MsG8eAB lenA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gOOZRG54; 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 j14-20020aa7ca4e000000b0050daa883555si5661105edt.684.2023.05.23.01.24.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:24:44 -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=gOOZRG54; 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 10470382CD41 for ; Tue, 23 May 2023 08:15:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10470382CD41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684829738; bh=jZC0mwqXK+612+IaLLu4cl99LIQVPYLb9vOCZyE6yPo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gOOZRG54Dj7A2X0Df+pWjenY+OEQvIUq41pJ9TxkGNNmRMBoUoJLqLD7BkElcVRuF rl8vnqnnX2ztjMU5VPH7pe3AQO2AToiD+5DKNBZFe3KLIC0LXJDeVazrOoIu0v6/Vw t9C4X7FUIGBx9UKoXKIjz7NmqVAzL1tYiaSe5oss= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 337253856092 for ; Tue, 23 May 2023 08:09:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 337253856092 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f6042d60b5so21236635e9.2 for ; Tue, 23 May 2023 01:09:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829367; x=1687421367; 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=jZC0mwqXK+612+IaLLu4cl99LIQVPYLb9vOCZyE6yPo=; b=lcoLGhdu3Er58H+kcUCtI0KHpzp1LMoNPQqfoXbp1GEiZ2mpWg1JwdPnqiQbWbqKDk XC1FHmQqXiOZijQCVzpQKuEqKD9zpTTmAIvHgMo6CqfNMI3n9RBwem1sNPmK0XFIoF6x BPQlob+Gy/g0D6k+yoKAFwg/FxP1RmuCPA5d0QG/y+YDGaf95PEj4VoyHjhEM7pdqNbs eq33qVhAhTIv9mz5qhYcYYMBoVcoht8rJwb9Cyo8mFWgu6RY1jPSz5WPy0Urd8P6HZQn MvkH2zacQOpKTvWdWIzCn3mw/aHw93dGiD4p8/gmAoCQqYVW2qtnQTk+9LKM44DLehYr vjmg== X-Gm-Message-State: AC+VfDy00iWDe2Avm8yUU18CCZ8xClxMAcax5+XPvKz3wENoFKIcqB2B KUTeMOOr4yPLN4avLGgr5DSAGVZ77Rt5HIWw/LnK4w== X-Received: by 2002:a7b:c414:0:b0:3f4:2610:5cc7 with SMTP id k20-20020a7bc414000000b003f426105cc7mr8866029wmi.9.1684829366823; Tue, 23 May 2023 01:09:26 -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 h1-20020a1ccc01000000b003eddc6aa5fasm14121506wmb.39.2023.05.23.01.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:09:26 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Rework fix for internal error on quantified expression with predicated type Date: Tue, 23 May 2023 10:09:25 +0200 Message-Id: <20230523080925.1875043-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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?1766672600077342962?= X-GMAIL-MSGID: =?utf-8?q?1766672600077342962?= From: Eric Botcazou It turns out that skipping compiler-generated block scopes is problematic when computing the public status of a subprogram, because this subprogram may end up being nested in the elaboration procedure of a package spec or body, in which case it may not be public. This replaces the original fix with a pair of Push_Scope/Pop_Scope in the Build_Predicate_Function procedure, as done elsewhere in similar cases. gcc/ada/ * sem_ch13.adb (Build_Predicate_Functions): If the current scope is not that of the type, push this scope and pop it at the end. * sem_util.ads (Current_Scope_No_Loops_No_Blocks): Delete. * sem_util.adb (Current_Scope_No_Loops_No_Blocks): Likewise. (Set_Public_Status): Call again Current_Scope. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch13.adb | 26 ++++++++++++++++++++------ gcc/ada/sem_util.adb | 27 +-------------------------- gcc/ada/sem_util.ads | 3 --- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index d1458f58784..983f877e001 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -9921,6 +9921,10 @@ package body Sem_Ch13 is procedure Build_Predicate_Function (Typ : Entity_Id; N : Node_Id) is Loc : constant Source_Ptr := Sloc (Typ); + Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; + Saved_IGR : constant Node_Id := Ignored_Ghost_Region; + -- Save the Ghost-related attributes to restore on exit + Expr : Node_Id; -- This is the expression for the result of the function. It is -- is build by connecting the component predicates with AND THEN. @@ -9939,6 +9943,9 @@ package body Sem_Ch13 is SId : Entity_Id; -- Its entity + Restore_Scope : Boolean; + -- True if the current scope must be restored on exit + Ancestor_Predicate_Function_Called : Boolean := False; -- Does this predicate function include a call to the -- predication function of an ancestor subtype? @@ -10190,12 +10197,6 @@ package body Sem_Ch13 is Replace_Type_References (N, Typ); end Replace_Current_Instance_References; - -- Local variables - - Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; - Saved_IGR : constant Node_Id := Ignored_Ghost_Region; - -- Save the Ghost-related attributes to restore on exit - -- Start of processing for Build_Predicate_Function begin @@ -10234,6 +10235,15 @@ package body Sem_Ch13 is return; end if; + -- Ensure that the declarations are added to the scope of the type + + if Scope (Typ) /= Current_Scope then + Push_Scope (Scope (Typ)); + Restore_Scope := True; + else + Restore_Scope := False; + end if; + -- The related type may be subject to pragma Ghost. Set the mode now to -- ensure that the predicate functions are properly marked as Ghost. @@ -10652,6 +10662,10 @@ package body Sem_Ch13 is end if; Restore_Ghost_Region (Saved_GM, Saved_IGR); + + if Restore_Scope then + Pop_Scope; + end if; end Build_Predicate_Function; ------------------------------------------ diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 22dc9376b92..9a0197cb45c 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6722,31 +6722,6 @@ package body Sem_Util is return S; end Current_Scope_No_Loops; - -------------------------------------- - -- Current_Scope_No_Loops_No_Blocks -- - -------------------------------------- - - function Current_Scope_No_Loops_No_Blocks return Entity_Id is - S : Entity_Id; - - begin - -- Examine the scope stack starting from the current scope and skip any - -- internally generated loops and blocks. - - S := Current_Scope; - while Present (S) and then S /= Standard_Standard loop - if Ekind (S) in E_Loop | E_Block - and then not Comes_From_Source (S) - then - S := Scope (S); - else - exit; - end if; - end loop; - - return S; - end Current_Scope_No_Loops_No_Blocks; - ------------------------ -- Current_Subprogram -- ------------------------ @@ -27763,7 +27738,7 @@ package body Sem_Util is ----------------------- procedure Set_Public_Status (Id : Entity_Id) is - S : constant Entity_Id := Current_Scope_No_Loops_No_Blocks; + S : constant Entity_Id := Current_Scope; function Within_HSS_Or_If (E : Entity_Id) return Boolean; -- Determines if E is defined within handled statement sequence or diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 3edc158c749..253d1dadeee 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -642,9 +642,6 @@ package Sem_Util is function Current_Scope_No_Loops return Entity_Id; -- Return the current scope ignoring internally generated loops - function Current_Scope_No_Loops_No_Blocks return Entity_Id; - -- Return the current scope ignoring internally generated loops and blocks - procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id;