GNAT implements Machine_Rounding as an alias for Rounding but, whereas
the implementation of the latter is in line when possible, that of the
former is always out of line, which is not aligned with the intent of
the Ada RM.

This changes the compiler to using for Machine_Rounding the same in line
implementation as Rounding when possible.

Running these commands:

  gcc -c f.adb -gnatD
  grep system f.adb.dg

On the following sources:

function F (Val : Float) return Integer is
begin
  return Integer (Float'Machine_Rounding (Val));
end;

Should execute silently.

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

2019-09-19  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * exp_attr.adb (Is_Inline_Floating_Point_Attribute): Treat
        Machine_Rounding as an alias for Rounding.
        * sem_res.adb (Simplify_Type_Conversion): Likewise.
--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -8360,13 +8360,13 @@ package body Exp_Attr is
          return False;
       end if;
 
-      --  Here we are in the integer conversion context
+      --  Here we are in the integer conversion context. We reuse Rounding for
+      --  Machine_Rounding as System.Fat_Gen, which is a permissible behavior.
 
-      --  Very probably we should also recognize the cases of Machine_Rounding
-      --  and unbiased rounding in this conversion context, but the back end is
-      --  not yet prepared to handle these cases ???
-
-      return Id = Attribute_Rounding or else Id = Attribute_Truncation;
+      return
+        Id = Attribute_Rounding
+          or else Id = Attribute_Machine_Rounding
+          or else Id = Attribute_Truncation;
    end Is_Inline_Floating_Point_Attribute;
 
 end Exp_Attr;

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -12439,7 +12439,8 @@ package body Sem_Res is
             --     ityp (x)
 
             --  with the Float_Truncate flag set to False or True respectively,
-            --  which is more efficient.
+            --  which is more efficient. We reuse Rounding for Machine_Rounding
+            --  as System.Fat_Gen, which is a permissible behavior.
 
             if Is_Floating_Point_Type (Opnd_Typ)
               and then
@@ -12448,6 +12449,7 @@ package body Sem_Res is
                             and then Conversion_OK (N)))
               and then Nkind (Operand) = N_Attribute_Reference
               and then Nam_In (Attribute_Name (Operand), Name_Rounding,
+                                                         Name_Machine_Rounding,
                                                          Name_Truncation)
             then
                declare

Reply via email to