diff mbox

[Ada] Handle compilation unit specific restrictions for subunits

Message ID 20120123084229.GA25224@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 23, 2012, 8:42 a.m. UTC
This patch corrects two problems introduced by the previous patch
to handle compilation unit specific restrictions. First if a subunit
is compiled on its own, it does not pick up compilation unit specific
restrictions from a configuration pragma file.

Seccond, if such restrictions appear in the parent unit, they were
improperly applied to subunits.

The following two tests test both these cases

with the following configuration pragmas file:

     1. pragma Restrictions (No_Implementation_Attributes);
     2. pragma Restrictions (SPARK);

and the following sources:

     1. procedure P is
     2.    procedure Q is separate;
     3. begin
     4.    Q;
     5. end;

     1. separate (P)
     2. procedure Q is
     3.    X : constant Integer := 0;
     4.    S : String := X'Img;
     5. begin
     6.    null;
     7. end Q;

Then if we compile p.adb we get messages for both units:

p.adb:5:04: violation of restriction "SPARK" at p.adc:2
             "end P" required
p-q.adb:4:04: violation of restriction "SPARK" at p.adc:2
               declaration of object of unconstrained type
              not allowed
p-q.adb:4:19: violation of restriction
              "No_Implementation_Attributes" at p.adc:1

If we compile the subunit on its own we get messages
only for the subunit:

p-q.adb:4:04: violation of restriction "SPARK" at p.adc:2
               declaration of object of unconstrained type
              not allowed
p-q.adb:4:19: violation of restriction
              "No_Implementation_Attributes" at p.adc:1

The second test tests the case of pragmas in the file:

     1. pragma Restrictions (No_Implementation_Attributes);
     2. pragma Restrictions (SPARK);
     3. procedure R is
     4.    procedure Q is separate;
     5. begin
     6.    Q;
     7. end;

     1. separate (R)
     2. procedure Q is
     3.    X : constant Integer := 0;
     4.    S : String := X'Img;
     5. begin
     6.    null;
     7. end Q;

If we compile the parent unit, we get only messages
for the parent unit:

     1. pragma Restrictions (No_Implementation_Attributes);
     2. pragma Restrictions (SPARK);
     3. procedure R is
     4.    procedure Q is separate;
     5. begin
     6.    Q;
     7. end;
           |
        >>> violation of restriction "SPARK" at line 2
        >>>  "end R" required

If we compile the subunit, we still get messages only
for the parent unit:

Compiling: r-q.adb

     1. separate (R)
     2. procedure Q is
     3.    X : constant Integer := 0;
     4.    S : String := X'Img;
     5. begin
     6.    null;
     7. end Q;

Compiling: r.adb

     1. pragma Restrictions (No_Implementation_Attributes);
     2. pragma Restrictions (SPARK);
     3. procedure R is
     4.    procedure Q is separate;
     5. begin
     6.    Q;
     7. end;
           |
        >>> violation of restriction "SPARK" at line 2
        >>>  "end R" required

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

2012-01-23  Robert Dewar  <dewar@adacore.com>

	* sem_ch10.adb (Analyze_Subunit): Properly save/restore cunit
	restrictions.
diff mbox

Patch

Index: sem_ch10.adb
===================================================================
--- sem_ch10.adb	(revision 183409)
+++ sem_ch10.adb	(working copy)
@@ -1962,6 +1962,12 @@ 
       Enclosing_Child : Entity_Id := Empty;
       Svg             : constant Suppress_Array := Scope_Suppress;
 
+      Save_Cunit_Restrictions : constant Save_Cunit_Boolean_Restrictions :=
+                                  Cunit_Boolean_Restrictions_Save;
+      --  Save non-partition wide restrictions before processing the subunit.
+      --  All subunits are analyzed with config restrictions reset and we need
+      --  to restore these saved values at the end.
+
       procedure Analyze_Subunit_Context;
       --  Capture names in use clauses of the subunit. This must be done before
       --  re-installing parent declarations, because items in the context must
@@ -2175,6 +2181,15 @@ 
    --  Start of processing for Analyze_Subunit
 
    begin
+      --  For subunit in main extended unit, we reset the configuration values
+      --  for the non-partition-wide restrictions. For other units reset them.
+
+      if In_Extended_Main_Source_Unit (N) then
+         Restore_Config_Cunit_Boolean_Restrictions;
+      else
+         Reset_Cunit_Boolean_Restrictions;
+      end if;
+
       if Style_Check then
          declare
             Nam : Node_Id := Name (Unit (N));
@@ -2280,6 +2295,10 @@ 
             end loop;
          end;
       end if;
+
+      --  Deal with restore of restrictions
+
+      Cunit_Boolean_Restrictions_Restore (Save_Cunit_Restrictions);
    end Analyze_Subunit;
 
    ----------------------------