https://gcc.gnu.org/g:c8d739794646ace3c19e078a7bca67c0e3bdfbdf

commit r16-1369-gc8d739794646ace3c19e078a7bca67c0e3bdfbdf
Author: Viljar Indus <in...@adacore.com>
Date:   Wed Mar 19 11:28:13 2025 +0200

    ada: Fix the detection of configuration pragmas
    
    Some pragma nodes like the ones for Assertion_Policy are
    replaced by a Null_Statement. This is not taken into account
    when analyzing if the pragma is a configuration pragma.
    
    gcc/ada/ChangeLog:
    
            * sem_prag.adb (Is_Configuration_Pragma): Check that nodes
            preceding the pragma are pragma nodes or originally were
            pragma nodes.

Diff:
---
 gcc/ada/sem_prag.adb | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 688ccc7c0072..2fc3698a67bf 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8087,10 +8087,26 @@ package body Sem_Prag is
       --  the test below also permits use in a configuration pragma file.
 
       function Is_Configuration_Pragma return Boolean is
+         function Is_Pragma_Node (Prg : Node_Id) return Boolean is
+           (Nkind (Prg) = N_Pragma
+            or else
+            (Present (Original_Node (Prg))
+             and then Nkind (Original_Node (Prg)) = N_Pragma));
+         --  Returns true whether the node is a pragma or was originally a
+         --  pragma.
+         --
+         --  Note that some pragmas like Assertion_Policy are rewritten as
+         --  Null_Statment nodes but we still need to make sure here that the
+         --  original node was a pragma node.
+
+         --  Local variables
+
          Lis : List_Id;
          Par : constant Node_Id := Parent (N);
          Prg : Node_Id;
 
+      --  Start of processing for Is_Configuration_Pragma
+
       begin
          --  Don't evaluate List_Containing (N) if Parent (N) could be
          --  an N_Aspect_Specification node.
@@ -8119,7 +8135,7 @@ package body Sem_Prag is
             loop
                if Prg = N then
                   return True;
-               elsif Nkind (Prg) /= N_Pragma then
+               elsif not Is_Pragma_Node (Prg) then
                   return False;
                end if;

Reply via email to