Patchwork [Ada] Do not replace Float'Range check by 'Valid

mail settings
Submitter Arnaud Charlet
Date June 22, 2010, 5:18 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/56540/
State New
Headers show


Arnaud Charlet - June 22, 2010, 5:18 p.m.
Testing X in Float'Range is a perfectly fine way to
test wether X is finite or not. Replacing the test
with X'Valid will also pessimize code on at least x86,
because it forces the operand to memory to avoid
excess precision.

-- This should compile without warning and not generate calls to 'Valid
function Is_Finite (X : Float) return Boolean is
   return X in Float'Range;
end Is_Finite;

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

2010-06-22  Geert Bosch  <>

	* exp_ch4.adb (Expand_N_In): Do not substitute a valid check for X in


Index: exp_ch4.adb
--- exp_ch4.adb	(revision 161171)
+++ exp_ch4.adb	(working copy)
@@ -4378,9 +4378,12 @@  package body Exp_Ch4 is
       --  Check case of explicit test for an expression in range of its
       --  subtype. This is suspicious usage and we replace it with a 'Valid
-      --  test and give a warning.
+      --  test and give a warning. For floating point types however, this
+      --  is a standard way to check for finite numbers, and using 'Valid
+      --  would typically be a pessimization
       if Is_Scalar_Type (Etype (Lop))
+        and then not Is_Floating_Point_Type (Etype (Lop))
         and then Nkind (Rop) in N_Has_Entity
         and then Etype (Lop) = Entity (Rop)
         and then Comes_From_Source (N)