public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Yannick Moy <moy@adacore.com>
Subject: [Ada] SPARK_Mode Off now allowed inside subprogram
Date: Thu, 04 Jul 2019 08:54:00 -0000	[thread overview]
Message-ID: <20190704085039.GA38925@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

The rule on SPARK_Mode have been modified so that it is now possible to
have a subprogram or package declared with SPARK_Mode Off inside a
subprogram.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-07-04  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* sem_prag.adb (Check_Library_Level_Entity): Update for new rule
	on SPARK_Mode.

gcc/testsuite/

	* gnat.dg/spark3.adb: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1421 bytes --]

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -23189,7 +23189,16 @@ package body Sem_Prag is
             --  Start of processing for Check_Library_Level_Entity
 
             begin
-               if not Is_Library_Level_Entity (E) then
+               --  A SPARK_Mode of On shall only apply to library-level
+               --  entities, except for those in generic instances, which are
+               --  ignored (even if the entity gets SPARK_Mode pragma attached
+               --  in the AST, its effect is not taken into account unless the
+               --  context already provides SPARK_Mode of On in GNATprove).
+
+               if Get_SPARK_Mode_From_Annotation (N) = On
+                 and then not Is_Library_Level_Entity (E)
+                 and then Instantiation_Location (Sloc (N)) = No_Location
+               then
                   Error_Msg_Name_1 := Pname;
                   Error_Msg_N (Fix_Error (Msg_1), N);
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/spark3.adb
@@ -0,0 +1,20 @@
+--  { dg-do compile }
+
+procedure SPARK3 (X : in out Integer) with SPARK_Mode is
+
+   procedure Q (X : in out Integer) with SPARK_Mode => Off is
+   begin
+      X := X + 1;
+   end Q;
+
+   procedure R (X : in out Integer);
+
+   procedure R (X : in out Integer) with SPARK_Mode => Off is
+   begin
+      Q (X);
+   end R;
+
+begin
+   R (X);
+   X := X + 1;
+end SPARK3;


                 reply	other threads:[~2019-07-04  8:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190704085039.GA38925@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=moy@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).