diff mbox

[Ada] Omit statement SCO for disabled pragma

Message ID 20110804122331.GA3078@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 4, 2011, 12:23 p.m. UTC
This change ensures that no statement SCO is emitted for a disabled pragma.

For the following compilation, the CS line shall contain only one entry
(for the assignment statement), and no entry for the (disabled) pragma Assert.

$ gcc -c -gnateS plop.adb
$ grep ^C plop.ali
C 1 plop.adb
CS 8:4-8:15

and when using -gnata, a P statement entry shall be generated, and in addition
a CP decision line:

$ gcc -c -gnateS -gnata plop.adb
$ grep ^C plop.ali
C 3 plop.adb
CS P7:4-7:28 8:4-8:15
CP 7:4 c7:19-7:28

procedure Plop
  (X, Y : Integer;
   Sum  : out Integer;
   UB   : Integer)
is
begin
   pragma Assert (X + Y <= UB);
   Sum := X + Y; 
end;

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

2011-08-04  Thomas Quinot  <quinot@adacore.com>

	* par_sco.adb (Traverse_Declarations_Or_Statements.Set_Statement_Entry):
	For a pragma (statement with C1 = 'P'), record the sloc of the pragma.
	* scos.ads: Update documentation accordingly.
	* put_scos.adb (Output_SCO_Line): Omit statement SCOs for disabled
	pragmas.
diff mbox

Patch

Index: par_sco.adb
===================================================================
--- par_sco.adb	(revision 177351)
+++ par_sco.adb	(working copy)
@@ -765,7 +765,10 @@ 
 
       Index := Condition_Pragma_Hash_Table.Get (Loc);
 
-      --  The test here for zero is to deal with possible previous errors
+      --  The test here for zero is to deal with possible previous errors, and
+      --  for the case of pragma statement SCOs, for which we always set the
+      --  Pragma_Sloc even if the particular pragma cannot be specifically
+      --  disabled.
 
       if Index /= 0 then
          pragma Assert (SCO_Table.Table (Index).C1 = 'P');
@@ -1071,14 +1074,23 @@ 
             end if;
 
             declare
-               SCE : SC_Entry renames SC.Table (J);
+               SCE         : SC_Entry renames SC.Table (J);
+               Pragma_Sloc : Source_Ptr := No_Location;
             begin
+               --  For the statement SCO for a pragma, set Pragma_Sloc so that
+               --  the SCO can be omitted if the pragma is disabled.
+
+               if SCE.Typ = 'P' then
+                  Pragma_Sloc := SCE.From;
+               end if;
+
                Set_Table_Entry
-                 (C1   => C1,
-                  C2   => SCE.Typ,
-                  From => SCE.From,
-                  To   => SCE.To,
-                  Last => (J = SC_Last));
+                 (C1          => C1,
+                  C2          => SCE.Typ,
+                  From        => SCE.From,
+                  To          => SCE.To,
+                  Last        => (J = SC_Last),
+                  Pragma_Sloc => Pragma_Sloc);
             end;
          end loop;
 
Index: scos.ads
===================================================================
--- scos.ads	(revision 177347)
+++ scos.ads	(working copy)
@@ -355,8 +355,9 @@ 
       Last : Boolean;
 
       Pragma_Sloc : Source_Ptr := No_Location;
-      --  For a SCO nested with a pragma Debug/Assert/PPC, location of pragma
-      --  (used for control of SCO output, value not recorded in ALI file).
+      --  For the statement SCO for a pragma, or for any expression SCO nested
+      --  in a pragma Debug/Assert/PPC, location of PRAGMA token (used for
+      --  control of SCO output, value not recorded in ALI file).
    end record;
 
    package SCO_Table is new GNAT.Table (
Index: put_scos.adb
===================================================================
--- put_scos.adb	(revision 177347)
+++ put_scos.adb	(working copy)
@@ -95,7 +95,8 @@ 
             pragma Assert (Start <= Stop);
 
             Output_SCO_Line : declare
-               T : SCO_Table_Entry renames SCO_Table.Table (Start);
+               T            : SCO_Table_Entry renames SCO_Table.Table (Start);
+               Continuation : Boolean;
 
             begin
                case T.C1 is
@@ -103,11 +104,26 @@ 
                   --  Statements
 
                   when 'S' =>
-                     Write_Info_Initiate ('C');
-                     Write_Info_Char ('S');
-
                      Ctr := 0;
+                     Continuation := False;
                      loop
+                        if SCO_Table.Table (Start).C2 = 'P'
+                             and then SCO_Pragma_Disabled
+                                        (SCO_Table.Table (Start).Pragma_Sloc)
+                        then
+                           goto Next_Statement;
+                        end if;
+
+                        if Ctr = 0 then
+                           Write_Info_Initiate ('C');
+                           if not Continuation then
+                              Write_Info_Char ('S');
+                              Continuation := True;
+                           else
+                              Write_Info_Char ('s');
+                           end if;
+                        end if;
+
                         Write_Info_Char (' ');
 
                         if SCO_Table.Table (Start).C2 /= ' ' then
@@ -115,22 +131,20 @@ 
                         end if;
 
                         Output_Range (SCO_Table.Table (Start));
-                        exit when SCO_Table.Table (Start).Last;
 
-                        Start := Start + 1;
-                        pragma Assert (SCO_Table.Table (Start).C1 = 's');
+                        --  Increment entry counter (up to 6 entries per line,
+                        --  continuation lines are marked Cs).
 
                         Ctr := Ctr + 1;
-
-                        --  Up to 6 items on a line, if more than 6 items,
-                        --  continuation lines are marked Cs.
-
                         if Ctr = 6 then
                            Write_Info_Terminate;
-                           Write_Info_Initiate ('C');
-                           Write_Info_Char ('s');
                            Ctr := 0;
                         end if;
+
+                     <<Next_Statement>>
+                        exit when SCO_Table.Table (Start).Last;
+                        Start := Start + 1;
+                        pragma Assert (SCO_Table.Table (Start).C1 = 's');
                      end loop;
 
                      Write_Info_Terminate;