From patchwork Mon Sep 15 13:01:08 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: 120263 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 BE2DA3858C52 for ; Mon, 15 Sep 2025 13:11:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE2DA3858C52 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=hAM50l5L X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id D8D2038560A3 for ; Mon, 15 Sep 2025 13:01:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8D2038560A3 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 D8D2038560A3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757941312; cv=none; b=EQC1V+CMJMgiJuejtHeSH+ECAfwxoOqN1hLUI1kL9QHWc+BAagax3u86aqv8jM/piR93sbxDpN+CgPtpfqgyacAnyuDEqmd6r8/GjAG+NMjgbBNxq+MHRanqwWHYz8TprRxcXZLT94ZKjsNFKyM6nj+6Xjg8925fjOBfhzXjNbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757941312; c=relaxed/simple; bh=lbr7nmQ7gXDNQnVUJVfRiHM7Yjcj4C+DYiClDoEe4T4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HrTUtu4T1x+wcSU4htFkn9llMydK2ug1xyiyAPuum2fJ9kfRd/uifu/EXnwaqnVFvU3GUqtKM9Q1WaDX/o+XZbHXykexGgGLe9ML3znkoUPfiBpU9pIn/HVA7mFI8fQAYBXTIAAndBAol76K4wH8KpKW0m/4MJTLXcDcYYO++cs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8D2038560A3 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3dae49b1293so2358300f8f.1 for ; Mon, 15 Sep 2025 06:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757941310; x=1758546110; 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=m62vQD+ZYXUBUV1IH18DNxS1USPQAZbxWZ4FZrkdVS8=; b=hAM50l5LdIMF3wtneW2cuqxX9KmNzimBPeksl/S3zeZe3dZpM9XOkVvh8U35D6ZiC7 kbA6dpyOGgBOclqecErHjCyQnLWfnNNRncxrJVM0u1WGcV0f069kk3OfwSlpwBDb+L63 MsYi0GIRfKpsDN4mil0DqBCyd+FPovwxR2kiLSylirEndUVSwyU8eDCjkW0Mh1BSL/a+ cyKaholRCTUQ9lOHMl1eIL9K1EUw57IKy288UPkKn4D7GGQC/dglLfY4UGWlxUBS+kql 0KR6KveQAo1EuQmESpbxJpoMvHhNGtEq5ypQyKtMCTsRfJI5t7LQTEv7vL8pnvl3K574 t2fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757941310; x=1758546110; 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: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IEpN6zPaS+eNXciILsr/NvOZc4zKJGHQfXRxDIGklhg6MGvmPLCqY9IPgnMznnxT4C21gBF4Q== X-Received: by 2002:a05:6000:2004:b0:3e9:9282:cfdf with SMTP id ffacd0b85a97d-3e99282d44bmr3795550f8f.41.1757941310424; Mon, 15 Sep 2025 06:01:50 -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-3ea4b52b7fcsm5428733f8f.33.2025.09.15.06.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 06:01:49 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED 02/27] ada: Disable ghost context checks before context is set Date: Mon, 15 Sep 2025 15:01:08 +0200 Message-ID: <20250915130135.2720894-2-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915130135.2720894-1-poulhies@adacore.com> References: <20250915130135.2720894-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 There are cases where we need to analyze the argument of the pragma in order to determine the ghostliness of the pragma. However during that analysis the ghost region of the pragma is not set yet so we cannot perform the ghost context checks at that moment. This patch provides the mechanism for disabling ghost context checks and disables them for pragma arguments that determine the ghostliness of the pragma. gcc/ada/ChangeLog: * ghost.adb (Check_Ghost_Context): Avoid context checks when they are globally disabled. * sem.ads (Ghost_Context_Checks_Disabled): New flag to control whether ghost context checks are activated or not. * sem_prag.adb (Analyze_Pragma): Disable ghost context checks for pragmas that determine their ghostliness based on one of its arguments. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/ghost.adb | 4 ++++ gcc/ada/sem.ads | 12 ++++++++++++ gcc/ada/sem_prag.adb | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index 4f1a0d9d6a46..ae20ef972c82 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -932,6 +932,10 @@ package body Ghost is -- Start of processing for Check_Ghost_Context begin + if Ghost_Context_Checks_Disabled then + return; + end if; + -- Class-wide pre/postconditions of ignored pragmas are preanalyzed -- to report errors on wrong conditions; however, ignored pragmas may -- also have references to ghost entities and we must disable checking diff --git a/gcc/ada/sem.ads b/gcc/ada/sem.ads index 611309775279..63cf1daad37d 100644 --- a/gcc/ada/sem.ads +++ b/gcc/ada/sem.ads @@ -307,6 +307,18 @@ package Sem is -- case. We could perhaps do a more accurate job and retain some of the -- warnings, but it is quite a tricky job. + Ghost_Context_Checks_Disabled : Boolean := False; + -- This flag controls whether ghost context related checks are enabled or + -- disabled. Typically they are enabled however they need to be disabled in + -- instances where the ghost region context has not been set. + -- + -- Typically this is done for pragmas where the ghostliness of the pragma + -- is determined by an entity specified as one of the arguments. In these + -- cases we need to analyze that argument before the pragma itself to + -- determine the ghostliness of the pragma. However at that point we have + -- not set the ghost region for the pragma in order to determine the ghost + -- context of the argument. + ----------------------------------- -- Handling of Check Suppression -- ----------------------------------- diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 661d4401d7a2..00c9b17ff6ee 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -6439,7 +6439,14 @@ package body Sem_Prag is end if; end if; + -- We are going to check the entity that determines the ghost + -- region of that pragma. We need to disable the checks for ghost + -- context since the ghost region can only be set after analyzing + -- this entity. + + Ghost_Context_Checks_Disabled := True; Analyze (Argx); + Ghost_Context_Checks_Disabled := False; if Nkind (Argx) not in N_Direct_Name and then (Nkind (Argx) /= N_Attribute_Reference @@ -9221,8 +9228,15 @@ package body Sem_Prag is Check_Optional_Identifier (Arg2, Name_Entity); Check_Arg_Is_Local_Name (Arg2); + -- We are going to check the entity that determines the ghost + -- region of that pragma. We need to disable the checks for ghost + -- context since the ghost region can only be set after analyzing + -- this entity. + + Ghost_Context_Checks_Disabled := True; Id := Get_Pragma_Arg (Arg2); Analyze (Id); + Ghost_Context_Checks_Disabled := False; if not Is_Entity_Name (Id) then Error_Pragma_Arg ("entity name required", Arg2); @@ -12022,7 +12036,15 @@ package body Sem_Prag is Check_Optional_Identifier (Arg2, Name_On); E_Id := Get_Pragma_Arg (Arg2); + + -- We are going to check the entity that determines the ghost + -- region of that pragma. We need to disable the checks for ghost + -- context since the ghost region can only be set after analyzing + -- this entity. + + Ghost_Context_Checks_Disabled := True; Analyze (E_Id); + Ghost_Context_Checks_Disabled := False; if not Is_Entity_Name (E_Id) then Error_Pragma_Arg @@ -15041,6 +15063,7 @@ package body Sem_Prag is Check_Ada_83_Warning; Check_No_Identifiers; Check_Arg_Count (1); + Check_Arg_Is_Local_Name (Arg1); if Debug_Flag_U then @@ -15048,8 +15071,16 @@ package body Sem_Prag is end if; C_Ent := Cunit_Entity (Current_Sem_Unit); + + -- We are going to check the entity that determines the ghost + -- region of that pragma. We need to disable the checks for ghost + -- context since the ghost region can only be set after analyzing + -- this entity. + + Ghost_Context_Checks_Disabled := True; Analyze (Get_Pragma_Arg (Arg1)); Nm := Entity (Get_Pragma_Arg (Arg1)); + Ghost_Context_Checks_Disabled := False; -- A pragma that applies to a Ghost entity becomes Ghost for the -- purposes of legality checks and removal of ignored Ghost code. @@ -22359,7 +22390,15 @@ package body Sem_Prag is while Present (Arg) loop Check_Arg_Is_Local_Name (Arg); Id := Get_Pragma_Arg (Arg); + + -- We are going to check the entity that determines the ghost + -- region of that pragma. We need to disable the checks for + -- ghost context since the ghost region can only be set after + -- analyzing this entity. + + Ghost_Context_Checks_Disabled := True; Analyze (Id); + Ghost_Context_Checks_Disabled := False; if not Is_Entity_Name (Id) then Error_Pragma_Arg ("entity name required", Arg);