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: Steve Baird <baird@adacore.com>
Subject: [COMMITTED] ada: Better error message for bad Discard_Names configuration pragma
Date: Thu,  5 Jan 2023 15:39:01 +0100	[thread overview]
Message-ID: <20230105143901.155499-1-poulhies@adacore.com> (raw)

From: Steve Baird <baird@adacore.com>

When a pragma Discard_Names is used as a configuration pragma, it does not
take an argument. If an argument is given, the resulting error message was
incorrect and confusing.

gcc/ada/

	* sem_prag.adb (Analyze_Pragma): Fix Is_Configuration_Pragma
	function to handle case where the pragma's parent is an
	N_Aspect_Specification node. In analyzing a Discard_Names pragma,
	do not assume that a nonzero number of arguments implies that the
	pragma is not a configuration pragma; that assumption only holds
	for legal programs.

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

---
 gcc/ada/sem_prag.adb | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index f3c23caeae4..555e09b74e9 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -7298,11 +7298,20 @@ package body Sem_Prag is
       --  the test below also permits use in a configuration pragma file.
 
       function Is_Configuration_Pragma return Boolean is
-         Lis : constant List_Id := List_Containing (N);
+         Lis : List_Id;
          Par : constant Node_Id := Parent (N);
          Prg : Node_Id;
 
       begin
+         --  Don't evaluate List_Containing (N) if Parent (N) could be
+         --  an N_Aspect_Specification node.
+
+         if not Is_List_Member (N) then
+            return False;
+         end if;
+
+         Lis := List_Containing (N);
+
          --  If no parent, then we are in the configuration pragma file,
          --  so the placement is definitely appropriate.
 
@@ -15729,8 +15738,13 @@ package body Sem_Prag is
 
             --  Deal with configuration pragma case
 
-            if Arg_Count = 0 and then Is_Configuration_Pragma then
-               Global_Discard_Names := True;
+            if Is_Configuration_Pragma then
+               if Arg_Count /= 0 then
+                  Error_Pragma
+                    ("nonzero number of arguments for configuration pragma%");
+               else
+                  Global_Discard_Names := True;
+               end if;
                return;
 
             --  Otherwise, check correct appropriate context
-- 
2.34.1


                 reply	other threads:[~2023-01-05 14:39 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=20230105143901.155499-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=baird@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).