]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Avoid marking a ghost pragma twice
authorViljar Indus <indus@adacore.com>
Fri, 1 Aug 2025 10:20:38 +0000 (13:20 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 9 Sep 2025 12:39:55 +0000 (14:39 +0200)
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.

gcc/ada/sem_prag.adb

index 00b78d9632fbeaeb9137bf4d92eb8c45ec8016b9..32da63fa8b4373ed03a758a3dadd565fa38bfd83 100644 (file)
@@ -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