https://gcc.gnu.org/g:43b631530d4e2d4be9bcebb70848aea50c535e6d

commit r16-3697-g43b631530d4e2d4be9bcebb70848aea50c535e6d
Author: Viljar Indus <[email protected]>
Date:   Fri Aug 1 13:20:38 2025 +0300

    ada: Avoid marking a ghost pragma twice
    
    Previously all assertion level pragmas were marked based on the
    current scope. Additionally some pragmas were marked afterwards
    based on the relevant entity e.g. Pre. This would lead to cases
    where a pragma was marked as both ignored and checked ghost pragma.
    
    Each pragma should get marked only once based on their individual
    semantics.
    
    gcc/ada/ChangeLog:
    
            * sem_prag.adb (Analyze_Pragma): Set Mark_Ghost_Code individually
            based on the semantics of each pragma.

Diff:
---
 gcc/ada/sem_prag.adb | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 00b78d9632fb..32da63fa8b43 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -8765,6 +8765,8 @@ package body Sem_Prag is
          Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
          Analyze_And_Resolve (Arg1x, Standard_Boolean);
 
+         Mark_Ghost_Pragma (N, Current_Scope);
+
          if CodePeer_Mode then
             Rewrite (N, Make_Null_Statement (Loc));
             return;
@@ -12749,12 +12751,6 @@ package body Sem_Prag is
          raise Pragma_Exit;
       end if;
 
-      --  Mark assertion pragmas as Ghost depending on their enclosing context
-
-      if Assertion_Expression_Pragma (Prag_Id) then
-         Mark_Ghost_Pragma (N, Current_Scope);
-      end if;
-
       --  Preset arguments
 
       Arg_Count := List_Length (Pragma_Argument_Associations (N));
@@ -14364,6 +14360,7 @@ package body Sem_Prag is
             Check_At_Most_N_Arguments (2);
             Gather_Associations (Names, Args);
             Check_Arg_Order (Names);
+            Mark_Ghost_Pragma (N, Current_Scope);
 
             --  Special processing for Loop_Invariant, Loop_Variant or for
             --  other cases where a Loop_Entry attribute is present. If the
@@ -15385,6 +15382,8 @@ package body Sem_Prag is
             --  the mode now to ensure that any nodes generated during analysis
             --  and expansion are marked as Ghost.
 
+            Mark_Ghost_Pragma (N, Current_Scope);
+
             Set_Ghost_Mode (N);
 
             GNAT_Pragma;
@@ -21580,6 +21579,7 @@ package body Sem_Prag is
             GNAT_Pragma;
             Check_At_Least_N_Arguments (1);
             Check_Loop_Pragma_Placement;
+            Mark_Ghost_Pragma (N, Current_Scope);
 
             --  Process all increasing / decreasing expressions

Reply via email to