[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2014 09:38:17 +0000 (11:38 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2014 09:38:17 +0000 (11:38 +0200)
2014-08-04  Robert Dewar  <dewar@adacore.com>

* checks.adb (Activate_Overflow_Check): Remove
Check_Float_Overflow processing.
(Apply_Scalar_Range_Check): Ditto.
(Generate_Range_Check): Ditto.
* exp_ch4.adb (Expand_N_Op_Add): Add call to
Check_Float_Op_Overflow.
(Expand_N_Op_Divide): ditto.
(Expand_N_Op_Multiply): ditto.
(Expand_N_Op_Subtract): ditto.
* exp_util.ads, exp_util.adb (Check_Float_Op_Overflow): New procedure.
* sem_attr.adb (Analyze_Attribute, case Pred): Make sure
Do_Range_Check is set for floating-point case in -gnatc or
GNATprove mode.
(Analyze_Attribute, case Succ): Make sure
Do_Range_Check is set for floating-point case in -gnatc or
GNATprove mode.
* sem_res.adb (Resolve_Type_Conversion): Make sure Do_Range_Check
flag is set for real to integer conversion in GNATprove or
-gnatc mode.

2014-08-04  Gary Dismukes  <dismukes@adacore.com>

* sem_ch13.adb (Analyze_Aspect_Specifications): Resolve
the expression of an Import or Export aspect as type Boolean
and require it to be static. Add ??? comment. Also, set the
Is_Exported flag when appropriate.

From-SVN: r213545

gcc/ada/ChangeLog
gcc/ada/checks.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_util.adb
gcc/ada/exp_util.ads
gcc/ada/sem_attr.adb
gcc/ada/sem_ch13.adb
gcc/ada/sem_res.adb

index d4e1dc8ae3d8ca81cac31e40e5dc81f234029a3d..39ace1f7878ef77019d30521aef947f95cc3d61c 100644 (file)
@@ -1,3 +1,32 @@
+2014-08-04  Robert Dewar  <dewar@adacore.com>
+
+       * checks.adb (Activate_Overflow_Check): Remove
+       Check_Float_Overflow processing.
+       (Apply_Scalar_Range_Check): Ditto.
+       (Generate_Range_Check): Ditto.
+       * exp_ch4.adb (Expand_N_Op_Add): Add call to
+       Check_Float_Op_Overflow.
+       (Expand_N_Op_Divide): ditto.
+       (Expand_N_Op_Multiply): ditto.
+       (Expand_N_Op_Subtract): ditto.
+       * exp_util.ads, exp_util.adb (Check_Float_Op_Overflow): New procedure.
+       * sem_attr.adb (Analyze_Attribute, case Pred): Make sure
+       Do_Range_Check is set for floating-point case in -gnatc or
+       GNATprove mode.
+       (Analyze_Attribute, case Succ): Make sure
+       Do_Range_Check is set for floating-point case in -gnatc or
+       GNATprove mode.
+       * sem_res.adb (Resolve_Type_Conversion): Make sure Do_Range_Check
+       flag is set for real to integer conversion in GNATprove or
+       -gnatc mode.
+
+2014-08-04  Gary Dismukes  <dismukes@adacore.com>
+
+       * sem_ch13.adb (Analyze_Aspect_Specifications): Resolve
+       the expression of an Import or Export aspect as type Boolean
+       and require it to be static. Add ??? comment. Also, set the
+       Is_Exported flag when appropriate.
+
 2014-08-04  Robert Dewar  <dewar@adacore.com>
 
        * exp_ch4.adb: Minor reformatting.
index f41df5466b746176fbc198990caf77e6e244bfc0..1f9493d1d18dc5b43171e5ec4fdecb2b7aca92ce 100644 (file)
@@ -396,10 +396,6 @@ package body Checks is
       if Present (Etype (N))
         and then Is_Floating_Point_Type (Etype (N))
         and then not Is_Constrained (Etype (N))
-
-        --  But do the check after all if float overflow checking enforced
-
-        and then not Check_Float_Overflow
       then
          return;
       end if;
@@ -2871,11 +2867,6 @@ package body Checks is
            and then not Has_Infinities (Target_Typ)
          then
             Enable_Range_Check (Expr);
-
-         --  Always do a range check for operators if option set
-
-         elsif Check_Float_Overflow and then Nkind (Expr) in N_Op then
-            Enable_Range_Check (Expr);
          end if;
       end if;
 
@@ -2984,9 +2975,9 @@ package body Checks is
 
       --  Normally, we only do range checks if the type is constrained. We do
       --  NOT want range checks for unconstrained types, since we want to have
-      --  infinities. Override this decision in Check_Float_Overflow mode.
+      --  infinities.
 
-         if Is_Constrained (S_Typ) or else Check_Float_Overflow then
+         if Is_Constrained (S_Typ) then
             Enable_Range_Check (Expr);
          end if;
 
@@ -6471,11 +6462,6 @@ package body Checks is
              or else
                (Is_Entity_Name (N)
                  and then Ekind (Entity (N)) = E_Enumeration_Literal))
-
-        --  Also do not apply this for floating-point if Check_Float_Overflow
-
-        and then not
-          (Is_Floating_Point_Type (Source_Type) and Check_Float_Overflow)
       then
          Set_Do_Range_Check (N, False);
          return;
index e0f76fc51167d8758472b4868037e6e709e4c2ca..0f4261fb7b99d30163f3523dcbf962821ed300df 100644 (file)
@@ -151,11 +151,11 @@ package body Exp_Ch4 is
       Bodies : List_Id) return Node_Id;
    --  Local recursive function used to expand equality for nested composite
    --  types. Used by Expand_Record/Array_Equality, Bodies is a list on which
-   --  to attach bodies of local functions that are created in the process.
-   --  It is the responsibility of the caller to insert those bodies at the
-   --  right place. Nod provides the Sloc value for generated code. Lhs and Rhs
-   --  are the left and right sides for the comparison, and Typ is the type of
-   --  the objects to compare.
+   --  to attach bodies of local functions that are created in the process. It
+   --  is the responsibility of the caller to insert those bodies at the right
+   --  place. Nod provides the Sloc value for generated code. Lhs and Rhs are
+   --  the left and right sides for the comparison, and Typ is the type of the
+   --  objects to compare.
 
    procedure Expand_Concatenate (Cnode : Node_Id; Opnds : List_Id);
    --  Routine to expand concatenation of a sequence of two or more operands
index 64523f2e4c6f18e38bc2d1f10d2558676a7a243c..c1fca54fe4928cc2971c9ab4681a63c3557a0900 100644 (file)
@@ -1633,6 +1633,60 @@ package body Exp_Util is
       return Build_Task_Image_Function (Loc, Decls, Stats, Res);
    end Build_Task_Record_Image;
 
+   -----------------------------
+   -- Check_Float_Op_Overflow --
+   -----------------------------
+
+   procedure Check_Float_Op_Overflow (N : Node_Id) is
+   begin
+      --  Return if no check needed
+
+      if not Check_Float_Overflow
+        or else not Is_Floating_Point_Type (Etype (N))
+      then
+         return;
+      end if;
+
+      --  Otherwise we replace the expression by
+
+      --  do Tnn : constant ftype := expression;
+      --     constraint_error when not Tnn'Valid;
+      --  in Tnn;
+
+      declare
+         Loc : constant Source_Ptr := Sloc (N);
+         Tnn : constant Entity_Id  := Make_Temporary (Loc, 'T', N);
+         Typ : constant Entity_Id  := Etype (N);
+
+      begin
+         --  Prevent recursion
+
+         Set_Analyzed (N);
+
+         --  Do the rewrite to include the check
+
+         Rewrite (N,
+           Make_Expression_With_Actions (Loc,
+             Actions    => New_List (
+               Make_Object_Declaration (Loc,
+                 Defining_Identifier => Tnn,
+                 Object_Definition   => New_Occurrence_Of (Typ, Loc),
+                 Constant_Present    => True,
+                 Expression          => Relocate_Node (N)),
+               Make_Raise_Constraint_Error (Loc,
+                 Condition =>
+                   Make_Op_Not (Loc,
+                     Right_Opnd =>
+                       Make_Attribute_Reference (Loc,
+                         Prefix         => New_Occurrence_Of (Tnn, Loc),
+                         Attribute_Name => Name_Valid)),
+                 Reason    => CE_Overflow_Check_Failed)),
+             Expression => New_Occurrence_Of (Tnn, Loc)));
+
+         Analyze_And_Resolve (N, Typ);
+      end;
+   end Check_Float_Op_Overflow;
+
    ----------------------------------
    -- Component_May_Be_Bit_Aligned --
    ----------------------------------
index a62ca9f101e4ac5439c59fb2b192f177ec2d64e9..cdc2a24adbd840c81652bd4cf15858d9bf4e320d 100644 (file)
@@ -276,6 +276,13 @@ package Exp_Util is
    --  is false, the call is for a stand-alone object, and the generated
    --  function itself must do its own cleanups.
 
+   procedure Check_Float_Op_Overflow (N : Node_Id);
+   --  Called where we could have a floating-point binary operator where we
+   --  must check for infinities if we are operating in Check_Float_Overflow
+   --  mode. Note that we don't need to worry about unary operator cases,
+   --  since for floating-point, abs, unary "-", and unary "+" can never
+   --  case overflow.
+
    function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean;
    --  This function is in charge of detecting record components that may
    --  cause trouble in the back end if an attempt is made to assign the
index 2fab55aafad3055f0bb19061ed3920b62c418085..cab75c945cda7c1c5dca75d0632196b8f864c5a7 100644 (file)
@@ -4808,10 +4808,8 @@ package body Sem_Attr is
          --  make an exception in Check_Float_Overflow mode.
 
          if Is_Floating_Point_Type (P_Type) then
-            if Check_Float_Overflow
-              and then not Range_Checks_Suppressed (P_Base_Type)
-            then
-               Enable_Range_Check (E1);
+            if not Range_Checks_Suppressed (P_Base_Type) then
+               Set_Do_Range_Check (E1);
             end if;
 
          --  If not modular type, test for overflow check required
@@ -5702,10 +5700,8 @@ package body Sem_Attr is
          --  make an exception in Check_Float_Overflow mode.
 
          if Is_Floating_Point_Type (P_Type) then
-            if Check_Float_Overflow
-              and then not Range_Checks_Suppressed (P_Base_Type)
-            then
-               Enable_Range_Check (E1);
+            if not Range_Checks_Suppressed (P_Base_Type) then
+               Set_Do_Range_Check (E1);
             end if;
 
          --  If not modular type, test for overflow check required
index 15bb5b3856e27e2f3e4b86f19f50af045e941622..3ef583621b7a7eddec031a0b09d4ab2332c18cfb 100644 (file)
@@ -2949,18 +2949,34 @@ package body Sem_Ch13 is
                      --  that verifed that there was a matching convention
                      --  is now obsolete.
 
-                     if A_Id = Aspect_Import then
-                        Set_Is_Imported (E);
+                     --  Resolve the expression of an Import or Export here,
+                     --  and require it to be of type Boolean and static. This
+                     --  is not quite right, because in general this should be
+                     --  delayed, but that seems tricky for these, because
+                     --  normally Boolean aspects are replaced with pragmas at
+                     --  the freeze point (in Make_Pragma_From_Boolean_Aspect),
+                     --  but in the case of these aspects we can't generate
+                     --  a simple pragma with just the entity name. ???
+
+                     if not Present (Expr)
+                       or else Is_True (Static_Boolean (Expr))
+                     then
+                        if A_Id = Aspect_Import then
+                           Set_Is_Imported (E);
 
-                        --  An imported entity cannot have an explicit
-                        --  initialization.
+                           --  An imported entity cannot have an explicit
+                           --  initialization.
 
-                        if Nkind (N) = N_Object_Declaration
-                          and then Present (Expression (N))
-                        then
-                           Error_Msg_N
-                             ("imported entities cannot be initialized "
-                              & "(RM B.1(24))", Expression (N));
+                           if Nkind (N) = N_Object_Declaration
+                             and then Present (Expression (N))
+                           then
+                              Error_Msg_N
+                                ("imported entities cannot be initialized "
+                                 & "(RM B.1(24))", Expression (N));
+                           end if;
+
+                        elsif A_Id = Aspect_Export then
+                           Set_Is_Exported (E);
                         end if;
                      end if;
 
index 87024ee92f56b952de7d4af42a8228148f2480e4..6708bc6157aa2c7b06efd70c1addbab00e7bab56 100644 (file)
@@ -10507,9 +10507,11 @@ package body Sem_Res is
 
       --  If at this stage we have a real to integer conversion, make sure
       --  that the Do_Range_Check flag is set, because such conversions in
-      --  general need a range check.
+      --  general need a range check. We only need this if expansion is off
+      --  or we are in GNATProve mode.
 
       if Nkind (N) = N_Type_Conversion
+        and then (GNATprove_Mode or not Expander_Active)
         and then Is_Integer_Type (Target_Typ)
         and then Is_Real_Type (Operand_Typ)
       then