]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add Assertion_Policy checks for assertion levels
authorViljar Indus <indus@adacore.com>
Tue, 2 Sep 2025 10:11:30 +0000 (13:11 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 15 Sep 2025 12:59:31 +0000 (14:59 +0200)
Implement SPARK RM 6.9(19) check:

An Assertion_Policy pragma specifying an Assertion_Level policy shall not occur
within a ghost subprogram or package associated to an assertion level which depends
on this level.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Add ghost level check to
Assertion_Policy.

gcc/ada/sem_prag.adb

index 9175490eca276f67494a6f7fe309d7da45ac9025..172dc3d6f3ecfc2bf68cebe28fe6088ff0bd8458 100644 (file)
@@ -14845,6 +14845,22 @@ package body Sem_Prag is
                            ("invalid assertion kind for pragma%",
                            Arg);
                      end if;
+
+                     --  An Assertion_Policy pragma specifying an
+                     --  Assertion_Level policy shall not occur within a ghost
+                     --  subprogram or package associated to an assertion level
+                     --  which depends on this level (SPARK RM 6.9(19)).
+
+                     if Ghost_Config.Ghost_Mode > None
+                       and then Is_Same_Or_Depends_On_Level
+                                  (Ghost_Config.Ghost_Mode_Assertion_Level,
+                                   Level)
+                     then
+                        Error_Msg_Name_2 := Chars (Level);
+                        Error_Pragma
+                          ("pragma % cannot appear within ghost subprogram or "
+                           & "package that depends on %");
+                     end if;
                   end if;
 
                   Check_Arg_Is_One_Of (Arg, Policy_Names);