From patchwork Thu Sep 11 09:18:53 2025 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: 120049 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 C2BB13858C62 for ; Thu, 11 Sep 2025 09:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2BB13858C62 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=CHYhZ6u1 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id A6BD13858420 for ; Thu, 11 Sep 2025 09:19:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6BD13858420 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 A6BD13858420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582373; cv=none; b=xX9u8dNdeCFVnvfPZW4cLGo8FVExuVL5C5cHn1NP6isKuTk0zycknZ4GKNvEEYN9NWbubbTDkx1pc7NGlb5CzZ8yIunSccro2WgTHSguItnUknf3WVUefUieXmPPto8hgiDLtfw/CY+Zo2oJZC1OUq2s0eOyGKyXLKRu4H8j8GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582373; c=relaxed/simple; bh=cUl+cah2oiowfDIhpUs6axPgjxYM80vEjuaQDit7z8w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lKICnZaXWVW87qfw/KrV4d2nB6CAtTdSI58y2TicN0NCKzYJLiwOgc3ndR5Jj4Gdz3eJR9AIZgrHWI2Ye6sUJcl58hX/h3VtIDVCrgXvcWeAtMq0RPHzTiW2/JbLBq7fk3vjKRss8lxcIo3RhPTd2l1pKNjNj6FEiN9fbZaNRGU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-45ddc7d5731so3422635e9.1 for ; Thu, 11 Sep 2025 02:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582372; x=1758187172; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+r7Hr+eLWhb+IfppmiIMxQqlEMcK7gVyHpWGhH5i6lM=; b=CHYhZ6u13jtNzjsJIatpVcKeQbYIM0lqOv88eOW8hI0N6ypXKxlhdJsssKQzG8mK2W 8GE3B0golPIBUi1MSSrvxFCkVFV07RtBhHhsnxGgXVmT5L/E5GXBHQauLTnSk3Bs8e9p WdEnbLqSkVo3BLrlNI5ViurJAGsqDAO98jvNwOocGcAdHFbeJTnklFhaPKrNOtiRZhnG pvaRuuaj03shwkN9Y2pGV/clImfn1f6DkK3P/DgJO7MniSL6ALYyPtF6Ro7HGseqKRad OoOPQbvK74xCy0MEim8veRxSyMWN7Z7kc44MfR3bgVURBHVifv4Sr83LMD86paAhVOQm +odQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582372; x=1758187172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+r7Hr+eLWhb+IfppmiIMxQqlEMcK7g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0DIuhQ== X-Received: by 2002:a05:600c:1f14:b0:45b:97e0:22a8 with SMTP id 5b1f17b1804b1-45dddecda9bmr159352115e9.22.1757582372272; Thu, 11 Sep 2025 02:19:32 -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 ffacd0b85a97d-3e7607cd27dsm1649971f8f.41.2025.09.11.02.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:31 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED 21/31] ada: Ignore ghost policy errors inside aspect Iterable Date: Thu, 11 Sep 2025 11:18:53 +0200 Message-ID: <20250911091904.1505690-21-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911091904.1505690-1-poulhies@adacore.com> References: <20250911091904.1505690-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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 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: Viljar Indus It is OK to define a checked ghost type with an iterable aspect that has ignored Iterable functions. gcc/ada/ChangeLog: * ghost.adb (Check_Ghost_Policy): Avoid triggering a ghost policy error if the policy is referenced within the Iterable aspect. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/ghost.adb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index 0fbcf20da7c1..0918d27daeb7 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -807,8 +807,28 @@ package body Ghost is ------------------------ procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id) is + function Is_From_Aspect_Iterable (Ref : Node_Id) return Boolean; + -- Returns true when the node is contained within an Iterable aspect. + + function Is_From_Aspect_Iterable (Ref : Node_Id) return Boolean is + P : Node_Id := Parent (Ref); + begin + while Present (P) loop + if Nkind (P) = N_Aspect_Specification then + return Get_Aspect_Id (P) = Aspect_Iterable; + end if; + P := Parent (P); + end loop; + return False; + end Is_From_Aspect_Iterable; + + -- Local variables + Applic_Policy : Ghost_Mode_Type := Ghost_Config.Ghost_Mode; Ghost_Region : constant Node_Id := Ghost_Config.Current_Region; + + -- Start of processing for Check_Ghost_Policy + begin -- The policy is allowed to change within renaming and instantiation -- statements. @@ -844,6 +864,14 @@ package body Ghost is Error_Msg_NE ("\& used # with ghost policy `Ignore`", Ref, Id); end if; + -- A ghost entity E shall not be referenced within an aspect + -- specification [(including an aspect-specifying pragma)] which + -- specifies an aspect of an entity that is either non-ghost or not + -- assertion-level-dependent on E except in the following cases the + -- specified aspect is either Global, Depends, Refined_Global, + -- Refined_Depends, Initializes, Refined_State, or Iterable (SPARK RM + -- 6.9(15)). + if No (Ghost_Region) or else (Nkind (Ghost_Region) = N_Pragma and then Get_Pragma_Id (Ghost_Region) @@ -853,6 +881,7 @@ package body Ghost is | Pragma_Refined_Depends | Pragma_Initializes | Pragma_Refined_State) + or else Is_From_Aspect_Iterable (Ref) then return; end if;