]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve error message on violation of SPARK_Mode rules
authorYannick Moy <moy@adacore.com>
Tue, 27 Jun 2023 09:49:09 +0000 (11:49 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 6 Jul 2023 11:36:09 +0000 (13:36 +0200)
SPARK_Mode On can only be used on library-level entities.
Improve the error message here.

gcc/ada/

* errout.ads: Add explain code.
* sem_prag.adb (Check_Library_Level_Entity): Refine error message
and add explain code.

gcc/ada/errout.ads
gcc/ada/sem_prag.adb

index 80dd7dfaead2024e09fccaec37e26d09f05a839f..2065d73614aab2574e3fe51270d1a96c81c49a33 100644 (file)
@@ -622,6 +622,7 @@ package Errout is
    GEC_Volatile_Non_Interfering_Context : constant := 0004;
    GEC_Required_Part_Of                 : constant := 0009;
    GEC_Ownership_Moved_Object           : constant := 0010;
+   GEC_SPARK_Mode_On_Not_Library_Level  : constant := 0011;
 
    ------------------------
    -- List Pragmas Table --
index c5810685dc318d1ad9fa11ca70e673c2c9ea3577..6de87fbaba9611e9db71996416c91f74a94980de 100644 (file)
@@ -24144,7 +24144,8 @@ package body Sem_Prag is
 
                --  Local variables
 
-               Msg_1 : constant String := "incorrect placement of pragma%";
+               Msg_1 : constant String :=
+                 "incorrect placement of pragma% with value ""On"" '[[]']";
                Msg_2 : Name_Id;
 
             --  Start of processing for Check_Library_Level_Entity
@@ -24161,6 +24162,7 @@ package body Sem_Prag is
                  and then Instantiation_Location (Sloc (N)) = No_Location
                then
                   Error_Msg_Name_1 := Pname;
+                  Error_Msg_Code := GEC_SPARK_Mode_On_Not_Library_Level;
                   Error_Msg_N (Fix_Error (Msg_1), N);
 
                   Name_Len := 0;