From patchwork Thu Sep 11 09:18:52 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: 120041 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 3B6B2385840F for ; Thu, 11 Sep 2025 09:31:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id C19AA385840E for ; Thu, 11 Sep 2025 09:19:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C19AA385840E 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 C19AA385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582373; cv=none; b=fdFCFtzf4+/gUkUoreBdrf3JtbIHC4TCugtxqK3/VbGMvfA8Z6wlcv2xqvBIZlWEpqdtp0k0+TY0dDVn81SfY4CVirn+QQo2TBwvsvzsXzN6v0SzwoODVy2vvGen/1mX+hiECOBbY36FGQwdXOzO2H2v2Sf5R9SGr0NzRRvKhMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582373; c=relaxed/simple; bh=MS8EWFwMW/wN3bVu5nf13svQm7L+2qlBTk628ndq5H0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fx6/TrrEMmyWzgfm5Tjssklqn3O6YcFLy//lGTIqEVc5BBPOXNfhAZHO8Fyz0BUqPKSXdAeTi/Qi2wvXC8mmMEwje1MT/4rl8znHdrUJLb8fhSqxwr0v2+bPKPNGe9ypFXaIH3Cpmul7XZ8L5/BdruXbd9ie0cA33wturJPXaf0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C19AA385840E 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=Brgq/UMa Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3e7622483beso171279f8f.3 for ; Thu, 11 Sep 2025 02:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582371; x=1758187171; 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=Qmt9X60DoCwo8msoSkznyIVwpuBwnZQwQc21XGkZXow=; b=Brgq/UMamd3IWSGSeE8/htGpJqRxjbReslJhoX63f0YCropCbRgWLw+BQx/he5moG6 sTl15KFvw0Ms6bDac1VugGhO/0wq3abxGIB/CnBeWXk3Xlsisvb/HHfaOG4uysVW6K23 NaGuszbG+/Zq9n0cLpqx8RJQuWkxDQf9JITq32u7MoxaVVGM2aYCdVcFDil/L9UpXFld Zf3EH6vYoFOlmoV3q2fdIXMXN774QJ32N8cnWZGzSDikPxI+RPCVQ859N/JD3fEly1EJ 4/A821Nr7peO5Ge6rcK6i/QnEdFrQbgKIE9XLWEDa/yiIA4YbZqPaeeGZqNsxrH4KNsy PHoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582371; x=1758187171; 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=Qmt9X60DoCwo8msoSkznyIVwpuBwnZQwQc21XGkZXow=;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L2zi17lVPQ== X-Received: by 2002:a05:6000:40c9:b0:3dc:280c:5f83 with SMTP id ffacd0b85a97d-3e642309219mr19172081f8f.5.1757582371440; Thu, 11 Sep 2025 02:19:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:30 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED 20/31] ada: Check ghost level dependencies inside assignments Date: Thu, 11 Sep 2025 11:18:52 +0200 Message-ID: <20250911091904.1505690-20-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.4 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 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 Check that entities on the RHS are ghost level dependent on the entities on the LHS of the assignemnt. gcc/ada/ChangeLog: * ghost.adb (Is_OK_Statement): Check the levels of the assignee with the levels of the entity are ghost level dependent. (Check_Assignement_Levels): New function for checking the level dependencies. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/ghost.adb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index bc646b22fbe5..0fbcf20da7c1 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -515,6 +515,10 @@ package body Ghost is function Is_OK_Statement (Stmt : Node_Id; Id : Entity_Id; Call_Arg : Node_Id) return Boolean is + procedure Check_Assignment_Levels (Assignee : Entity_Id); + -- Check that a ghost entity on the RHS of the assignment is + -- assertion level dependent on the LHS. + procedure Check_Procedure_Call_Policies (Callee : Entity_Id); -- Check that -- * the a checked call argument is not modified by an ignored @@ -528,6 +532,39 @@ package body Ghost is -- Check that Call_Arg was used in the call and that the formal -- for that argument was either out or in-out. + ----------------------------- + -- Check_Assignment_Levels -- + ----------------------------- + + procedure Check_Assignment_Levels (Assignee : Entity_Id) is + Assignee_Level : constant Entity_Id := + Ghost_Assertion_Level (Assignee); + Id_Level : constant Entity_Id := + Ghost_Assertion_Level (Id); + begin + -- SPARK RM 6.9 (13) A ghost entity E shall only be referenced + -- within an assignment statement whose target is a ghost + -- variable that is assertion-level-dependent on E. + + if not Is_Assertion_Level_Dependent (Id_Level, Assignee_Level) + then + Error_Msg_Sloc := Sloc (Ghost_Ref); + + Error_Msg_N (Assertion_Level_Error_Msg, Ghost_Ref); + Error_Msg_Name_1 := Chars (Id_Level); + Error_Msg_NE ("\& has assertion level %", Ghost_Ref, Id); + Error_Msg_Name_1 := Chars (Assignee_Level); + Error_Msg_Node_2 := Assignee; + Error_Msg_NE + ("\& is modifying & with %", Ghost_Ref, Id); + Error_Msg_Name_1 := Chars (Assignee_Level); + Error_Msg_NE + ("\assertion level of & should depend on %", + Ghost_Ref, + Id); + end if; + end Check_Assignment_Levels; + ----------------------------------- -- Check_Procedure_Call_Policies -- ----------------------------------- @@ -619,6 +656,8 @@ package body Ghost is if Nkind (Stmt) = N_Assignment_Statement then if Is_Ghost_Assignment (Stmt) then + Check_Assignment_Levels + (Get_Enclosing_Ghost_Entity (Name (Stmt))); return True; end if;