[Ada] Fix regression of ACATS c46032a with CCG back end
authorJavier Miranda <miranda@adacore.com>
Mon, 28 May 2018 08:55:42 +0000 (08:55 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 28 May 2018 08:55:42 +0000 (08:55 +0000)
2018-05-28  Javier Miranda  <miranda@adacore.com>

gcc/ada/

* exp_ch4.adb (Real_Range_Check): Add a temporary to store the integer
value when converting a float value to a fixed-point value. This is
required for CCG because it handles fixed-point types by means of
unsigned integer type variables. The range check is now performed using
the integer value stored in this temporary.

From-SVN: r260837

gcc/ada/ChangeLog
gcc/ada/exp_ch4.adb

index 19cb29682eba4f72b8a2628a57bc0484cd141aea..c00a76df1c894ad41dab16b3ab833ccfb828629b 100644 (file)
@@ -1,3 +1,11 @@
+2018-05-28  Javier Miranda  <miranda@adacore.com>
+
+       * exp_ch4.adb (Real_Range_Check): Add a temporary to store the integer
+       value when converting a float value to a fixed-point value. This is
+       required for CCG because it handles fixed-point types by means of
+       unsigned integer type variables. The range check is now performed using
+       the integer value stored in this temporary.
+
 2018-05-28  Yannick Moy  <moy@adacore.com>
 
        * sem_util.adb (Is_OK_Volatile_Context): Add attributes First, Last and
index 508123dd13b70362dccd74b8c6800ff544e7c9fa..517a8da65bdaa420111dd2f32c94fed5ab68d4e5 100644 (file)
@@ -11096,8 +11096,10 @@ package body Exp_Ch4 is
             --  conversion to the target fixed-point type.
 
             declare
-               Int_Type : Entity_Id;
                Bfx_Type : constant Entity_Id := Base_Type (Target_Type);
+               Expr_Id  : constant Entity_Id :=
+                            Make_Temporary (Loc, 'T', Conv);
+               Int_Type : Entity_Id;
 
             begin
                if RM_Size (Bfx_Type) > RM_Size (Standard_Integer) then
@@ -11112,15 +11114,29 @@ package body Exp_Ch4 is
                   Int_Type := Standard_Short_Integer;
                end if;
 
+               --  Generate a temporary with the integer value. Required in the
+               --  CCG compiler to ensure that runtime checks reference this
+               --  integer expression (instead of the resulting fixed-point
+               --  value) because fixed-point values are handled by means of
+               --  unsigned integer types).
+
+               Insert_Action (N,
+                 Make_Object_Declaration (Loc,
+                   Defining_Identifier => Expr_Id,
+                   Object_Definition   => New_Occurrence_Of (Int_Type, Loc),
+                   Constant_Present    => True,
+                   Expression          =>
+                     Convert_To (Int_Type, Expression (Conv))));
+
                --  Create integer objects for range checking of result.
 
                Lo_Arg := Unchecked_Convert_To (Int_Type,
-                           New_Occurrence_Of (Tnn, Loc));
+                           New_Occurrence_Of (Expr_Id, Loc));
                Lo_Val := Make_Integer_Literal (Loc,
                            Corresponding_Integer_Value (Lo));
 
                Hi_Arg := Unchecked_Convert_To (Int_Type,
-                           New_Occurrence_Of (Tnn, Loc));
+                           New_Occurrence_Of (Expr_Id, Loc));
                Hi_Val := Make_Integer_Literal (Loc,
                            Corresponding_Integer_Value (Hi));
 
@@ -11132,7 +11148,7 @@ package body Exp_Ch4 is
                            Subtype_Mark =>
                              New_Occurrence_Of (Target_Type, Loc),
                            Expression   =>
-                             Convert_To (Int_Type, Expression (Conv)));
+                             New_Occurrence_Of (Expr_Id, Loc));
             end;
 
          else  -- For all other conversions