aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2022-12-14 09:54:08 -0800
committerMarc Poulhiès <poulhies@adacore.com>2023-01-05 15:29:58 +0100
commit0776fec1557f60e256cd18a5456ee5ad04cf4262 (patch)
treed5bee5865e85e69c8fe1120c83511f1c9df812d1
parent0a8824f7025c2fae0dd11131043e3029c9ccadec (diff)
downloadgcc-0776fec1557f60e256cd18a5456ee5ad04cf4262.zip
gcc-0776fec1557f60e256cd18a5456ee5ad04cf4262.tar.gz
gcc-0776fec1557f60e256cd18a5456ee5ad04cf4262.tar.bz2
ada: Better error message for bad Discard_Names configuration pragma
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.
-rw-r--r--gcc/ada/sem_prag.adb20
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index f3c23ca..555e09b 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