[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Mon, 18 Apr 2016 12:33:46 +0000 (14:33 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 18 Apr 2016 12:33:46 +0000 (14:33 +0200)
2016-04-18  Arnaud Charlet  <charlet@adacore.com>

* osint-c.ads, osint-c.adb (Delete_C_File, Delete_H_File): New.
* gnat1drv.adb (Gnat1drv): Delete old C files before regenerating them.
* debug.adb: Reserve -gnatd.4 to force generation of C files.

2016-04-18  Yannick Moy  <moy@adacore.com>

* sem_eval.adb (Eval_Arithmetic_Op): Do not issue error on static
division by zero, instead possibly issue a warning.
* sem_res.adb (Resolve_Arithmetic_Op): Do not issue error on
static division by zero, instead add check flag on original
expression.
* sem_util.adb, sem_util.ads (Compile_Time_Constraint_Error):
Only issue error when both SPARK_Mode is On and Warn is False.

2016-04-18  Yannick Moy  <moy@adacore.com>

* checks.adb (Apply_Scalar_Range_Check): Force
warning instead of error when SPARK_Mode is On, on index out of
bounds, and set check flag for GNATprove.

From-SVN: r235138

gcc/ada/ChangeLog
gcc/ada/checks.adb
gcc/ada/debug.adb
gcc/ada/gnat1drv.adb
gcc/ada/osint-c.adb
gcc/ada/osint-c.ads
gcc/ada/sem_eval.adb
gcc/ada/sem_res.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads

index 11cbcb083b14bc7437726af86f73498982760304..2b8e6aeeb788af9f61d2591de7180826f5c7cae0 100644 (file)
@@ -1,3 +1,25 @@
+2016-04-18  Arnaud Charlet  <charlet@adacore.com>
+
+       * osint-c.ads, osint-c.adb (Delete_C_File, Delete_H_File): New.
+       * gnat1drv.adb (Gnat1drv): Delete old C files before regenerating them.
+       * debug.adb: Reserve -gnatd.4 to force generation of C files.
+
+2016-04-18  Yannick Moy  <moy@adacore.com>
+
+       * sem_eval.adb (Eval_Arithmetic_Op): Do not issue error on static
+       division by zero, instead possibly issue a warning.
+       * sem_res.adb (Resolve_Arithmetic_Op): Do not issue error on
+       static division by zero, instead add check flag on original
+       expression.
+       * sem_util.adb, sem_util.ads (Compile_Time_Constraint_Error):
+       Only issue error when both SPARK_Mode is On and Warn is False.
+
+2016-04-18  Yannick Moy  <moy@adacore.com>
+
+       * checks.adb (Apply_Scalar_Range_Check): Force
+       warning instead of error when SPARK_Mode is On, on index out of
+       bounds, and set check flag for GNATprove.
+
 2016-04-18  Hristian Kirtchev  <kirtchev@adacore.com>
 
        * sem_prag.adb (Check_In_Out_States.Check_Constituent_Usage):
index a3ea4770c64d02d25f0d3f53975173e8aa8bbd1f..e6eab0c3b0d9fba8d9ba7830601d0050da759b41 100644 (file)
@@ -2749,19 +2749,22 @@ package body Checks is
       --  Set to True if Expr should be regarded as a real value even though
       --  the type of Expr might be discrete.
 
-      procedure Bad_Value;
-      --  Procedure called if value is determined to be out of range
+      procedure Bad_Value (Warn : Boolean := False);
+      --  Procedure called if value is determined to be out of range. Warn is
+      --  True to force a warning instead of an error, even when SPARK_Mode is
+      --  On.
 
       ---------------
       -- Bad_Value --
       ---------------
 
-      procedure Bad_Value is
+      procedure Bad_Value (Warn : Boolean := False) is
       begin
          Apply_Compile_Time_Constraint_Error
            (Expr, "value not in range of}??", CE_Range_Check_Failed,
-            Ent => Target_Typ,
-            Typ => Target_Typ);
+            Ent  => Target_Typ,
+            Typ  => Target_Typ,
+            Warn => Warn);
       end Bad_Value;
 
    --  Start of processing for Apply_Scalar_Range_Check
@@ -2968,18 +2971,17 @@ package body Checks is
 
                   if Lov > Hiv then
 
-                     --  In GNATprove mode, do not issue a message in that case
-                     --  (which would be an error stopping analysis), as this
-                     --  likely corresponds to deactivated code based on a
-                     --  given configuration (say, dead code inside a loop over
-                     --  the empty range). Instead, we enable the range check
-                     --  so that GNATprove will issue a message if it cannot be
-                     --  proved.
+                     --  When SPARK_Mode is On, force a warning instead of
+                     --  an error in that case, as this likely corresponds
+                     --  to deactivated code.
+
+                     Bad_Value (Warn => SPARK_Mode = On);
+
+                     --  In GNATprove mode, we enable the range check so that
+                     --  GNATprove will issue a message if it cannot be proved.
 
                      if GNATprove_Mode then
                         Enable_Range_Check (Expr);
-                     else
-                        Bad_Value;
                      end if;
 
                      return;
index b38b82b102c8a04cf088352c1ebdaac6d89a9356..52de7a1405df46710666237434c5733b90d258d6 100644 (file)
@@ -158,7 +158,7 @@ package body Debug is
    --  d.1  Enable unnesting of nested procedures
    --  d.2  Allow statements in declarative part
    --  d.3  Output debugging information from Exp_Unst
-   --  d.4
+   --  d.4  Do not delete generated C file in case of errors
    --  d.5  Do not generate imported subprogram definitions in C code
    --  d.6
    --  d.7
@@ -762,6 +762,9 @@ package body Debug is
    --  d.3  Output debugging information from Exp_Unst, including the name of
    --       any unreachable subprograms that get deleted.
 
+   --  d.4  By default in case of an error during C generation, the .c or .h
+   --       file is delete. This flag keeps the C file.
+
    --  d.5  By default a subprogram imported generates a subprogram profile.
    --       This debug flag disables this generation when generating C code,
    --       assuming a proper #include will be used instead.
index 220ad93f12946844abca491226c0ff753fd20ce5..bc52f41ae913614737214ff941a2beff532114e8 100644 (file)
@@ -46,6 +46,7 @@ with Namet;    use Namet;
 with Nlists;
 with Opt;      use Opt;
 with Osint;    use Osint;
+with Osint.C;  use Osint.C;
 with Output;   use Output;
 with Par_SCO;
 with Prepcomp;
@@ -1078,6 +1079,13 @@ begin
          Comperr.Delete_SCIL_Files;
       end if;
 
+      --  Ditto for old C files before regenerating new ones
+
+      if Generate_C_Code then
+         Delete_C_File;
+         Delete_H_File;
+      end if;
+
       --  Exit if compilation errors detected
 
       Errout.Finalize (Last_Call => False);
index a24a5a73894b90b54085fb7e02c4f2a34fc93c63..919f188a8e4d3ce00f0661ffa7571791298e0888 100644 (file)
@@ -292,6 +292,28 @@ package body Osint.C is
       end if;
    end Debug_File_Eol_Length;
 
+   -------------------
+   -- Delete_C_File --
+   -------------------
+
+   procedure Delete_C_File is
+      Dummy : Boolean;
+   begin
+      Set_File_Name ("c");
+      Delete_File (Name_Buffer (1 .. Name_Len), Dummy);
+   end Delete_C_File;
+
+   -------------------
+   -- Delete_H_File --
+   -------------------
+
+   procedure Delete_H_File is
+      Dummy : Boolean;
+   begin
+      Set_File_Name ("h");
+      Delete_File (Name_Buffer (1 .. Name_Len), Dummy);
+   end Delete_H_File;
+
    ---------------------------------
    -- Get_Output_Object_File_Name --
    ---------------------------------
index 6819ec037ad15db69e991d7f30b9b6e80dd27d84..54ffb01f6014b432467dccdc5a0fdbb1637ac184 100644 (file)
@@ -159,7 +159,7 @@ package Osint.C is
    --------------------------
 
    --  These routines are used by the compiler when the C translation option
-   --  is activated to write *.c and *.h files to the current object directory.
+   --  is activated to write *.c or *.h files to the current object directory.
    --  Each routine exists in a C and an H form for the two kinds of files.
    --  Only one of these files can be written at a time. Note that the files
    --  are written via the Output package routines, using Output_FD.
@@ -175,6 +175,11 @@ package Osint.C is
    --  Closes the file created by Create_C_File or Create_H file, flushing any
    --  buffers etc. from writes by Write_C_File and Write_H_File;
 
+   procedure Delete_C_File;
+   procedure Delete_H_File;
+   --  Deletes the .c or .h file corresponding to the source file which is
+   --  currently being compiled.
+
    ----------------------
    -- List File Output --
    ----------------------
index 67d464c772f107dfab4fd7e9ba77a545bc264cdb..9703943bdd1ea6693c39cf724b0b1e1595d09def 100644 (file)
@@ -1885,9 +1885,14 @@ package body Sem_Eval is
                   --  division, rem and mod if the right operand is zero.
 
                   if Right_Int = 0 then
+
+                     --  When SPARK_Mode is On, force a warning instead of
+                     --  an error in that case, as this likely corresponds
+                     --  to deactivated code.
+
                      Apply_Compile_Time_Constraint_Error
                        (N, "division by zero", CE_Divide_By_Zero,
-                        Warn => not Stat);
+                        Warn => not Stat or SPARK_Mode = On);
                      Set_Raises_Constraint_Error (N);
                      return;
 
@@ -1903,10 +1908,16 @@ package body Sem_Eval is
                   --  division, rem and mod if the right operand is zero.
 
                   if Right_Int = 0 then
+
+                     --  When SPARK_Mode is On, force a warning instead of
+                     --  an error in that case, as this likely corresponds
+                     --  to deactivated code.
+
                      Apply_Compile_Time_Constraint_Error
                        (N, "mod with zero divisor", CE_Divide_By_Zero,
-                        Warn => not Stat);
+                        Warn => not Stat or SPARK_Mode = On);
                      return;
+
                   else
                      Result := Left_Int mod Right_Int;
                   end if;
@@ -1917,9 +1928,14 @@ package body Sem_Eval is
                   --  division, rem and mod if the right operand is zero.
 
                   if Right_Int = 0 then
+
+                     --  When SPARK_Mode is On, force a warning instead of
+                     --  an error in that case, as this likely corresponds
+                     --  to deactivated code.
+
                      Apply_Compile_Time_Constraint_Error
                        (N, "rem with zero divisor", CE_Divide_By_Zero,
-                        Warn => not Stat);
+                        Warn => not Stat or SPARK_Mode = On);
                      return;
 
                   else
index c12356cae32d7d85b76731f15da458b4217f09d4..67807723a920a273ef825e690139882e4f237c61 100644 (file)
@@ -5440,7 +5440,9 @@ package body Sem_Res is
                              and then Expr_Value_R (Rop) = Ureal_0))
             then
                --  Specialize the warning message according to the operation.
-               --  The following warnings are for the case
+               --  When SPARK_Mode is On, force a warning instead of an error
+               --  in that case, as this likely corresponds to deactivated
+               --  code. The following warnings are for the case
 
                case Nkind (N) is
                   when N_Op_Divide =>
@@ -5459,23 +5461,26 @@ package body Sem_Res is
                           ("float division by zero, may generate "
                            & "'+'/'- infinity??", Right_Opnd (N));
 
-                        --  For all other cases, we get a Constraint_Error
+                     --  For all other cases, we get a Constraint_Error
 
                      else
                         Apply_Compile_Time_Constraint_Error
                           (N, "division by zero??", CE_Divide_By_Zero,
-                           Loc => Sloc (Right_Opnd (N)));
+                           Loc  => Sloc (Right_Opnd (N)),
+                           Warn => SPARK_Mode = On);
                      end if;
 
                   when N_Op_Rem =>
                      Apply_Compile_Time_Constraint_Error
                        (N, "rem with zero divisor??", CE_Divide_By_Zero,
-                        Loc => Sloc (Right_Opnd (N)));
+                        Loc  => Sloc (Right_Opnd (N)),
+                        Warn => SPARK_Mode = On);
 
                   when N_Op_Mod =>
                      Apply_Compile_Time_Constraint_Error
                        (N, "mod with zero divisor??", CE_Divide_By_Zero,
-                        Loc => Sloc (Right_Opnd (N)));
+                        Loc  => Sloc (Right_Opnd (N)),
+                        Warn => SPARK_Mode = On);
 
                   --  Division by zero can only happen with division, rem,
                   --  and mod operations.
@@ -5484,6 +5489,13 @@ package body Sem_Res is
                      raise Program_Error;
                end case;
 
+               --  In GNATprove mode, we enable the division check so that
+               --  GNATprove will issue a message if it cannot be proved.
+
+               if GNATprove_Mode then
+                  Activate_Division_Check (N);
+               end if;
+
             --  Otherwise just set the flag to check at run time
 
             else
index 1146b9dfb1e4fc4c293f1506af9c10b197f4849e..348da03b26fa915d5a1221d8b75cf32d106c9b40 100644 (file)
@@ -4574,9 +4574,16 @@ package body Sem_Util is
 
    begin
       --  If this is a warning, convert it into an error if we are in code
-      --  subject to SPARK_Mode being set ON.
+      --  subject to SPARK_Mode being set On, unless Warn is True to force a
+      --  warning. The rationale is that a compile-time constraint error should
+      --  lead to an error instead of a warning when SPARK_Mode is On, but in
+      --  a few cases we prefer to issue a warning and generate both a suitable
+      --  run-time error in GNAT and a suitable check message in GNATprove.
+      --  Those cases are those that likely correspond to deactivated SPARK
+      --  code, so that this kind of code can be compiled and analyzed instead
+      --  of being rejected.
 
-      Error_Msg_Warn := SPARK_Mode /= On;
+      Error_Msg_Warn := Warn or SPARK_Mode /= On;
 
       --  A static constraint error in an instance body is not a fatal error.
       --  we choose to inhibit the message altogether, because there is no
@@ -4648,8 +4655,6 @@ package body Sem_Util is
          --  evaluated.
 
          if not Is_Statically_Unevaluated (N) then
-            Error_Msg_Warn := SPARK_Mode /= On;
-
             if Present (Ent) then
                Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
             else
index d8a9b52d34aa5cf08f310ddcc77af79fbf623a47..494a9e4d39cfc1121d274e1b4bb35c98475a13b5 100644 (file)
@@ -135,7 +135,9 @@ package Sem_Util is
    --  is present, this is used instead. Warn is normally False. If it is
    --  True then the message is treated as a warning even though it does
    --  not end with a ? (this is used when the caller wants to parameterize
-   --  whether an error or warning is given).
+   --  whether an error or warning is given), or when the message should be
+   --  treated as a warning even when SPARK_Mode is On (which otherwise would
+   --  force an error).
 
    function Async_Readers_Enabled (Id : Entity_Id) return Boolean;
    --  Given the entity of an abstract state or a variable, determine whether