public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITED] ada: Fix spurious warning on unreferenced refinement constituents
Date: Thu,  6 Oct 2022 11:25:44 +0200	[thread overview]
Message-ID: <20221006092544.260196-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

Listing an object as a state refinement constituent shouldn't be
considered to be a reference, at least from the point of view of the
machinery for detecting objects that are never referenced or written
without being referenced.

This patch fixes a spurious warning that rarely occurred in practice but
was annoyingly emitted for minimal reproducers for issues related to
state abstractions.

Note: there are other pragmas that should be similarly recognized (e.g.
Depends, Global and their refined variants), but recognizing them
efficiently probably requires a dedicated utility routine (i.e. to avoid
traversal of the parent chain for every kind of pragma).

gcc/ada/

	* sem_prag.adb
	(Sig_Pragma): Change flag for pragma Refined_State to mean "not
	significant"; this is primarily for documentation, because the
	exact value of the flag is not really taken into account for
	Refined_State.
	(Is_Non_Significant_Pragma_Reference): Add special handling for
	pragma Refined_State.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_prag.adb | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 77ff68e23cb..0c3dd815263 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31608,7 +31608,7 @@ package body Sem_Prag is
       Pragma_Refined_Depends                => -1,
       Pragma_Refined_Global                 => -1,
       Pragma_Refined_Post                   => -1,
-      Pragma_Refined_State                  => -1,
+      Pragma_Refined_State                  =>  0,
       Pragma_Relative_Deadline              =>  0,
       Pragma_Remote_Access_Type             => -1,
       Pragma_Remote_Call_Interface          => -1,
@@ -31713,6 +31713,15 @@ package body Sem_Prag is
       P := Parent (N);
 
       if Nkind (P) /= N_Pragma_Argument_Association then
+
+         --  References within pragma Refined_State are not significant. They
+         --  can't be recognized using pragma argument number, because they
+         --  appear inside refinement clauses that rely on aggregate syntax.
+
+         if In_Pragma_Expression (N, Name_Refined_State) then
+            return True;
+         end if;
+
          return False;
 
       else
-- 
2.34.1


                 reply	other threads:[~2022-10-06  9:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221006092544.260196-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).