For operations on unconstrained floating-point values, we do not want overflow checks (since we expect to generate and handle IEEE INF and NaN values). This corrects a problem where such checks were being set if integer overflow was enabled. The following test when executed:
1. with Ada.Float_Text_IO; 2. with Ada.Long_Long_Float_Text_IO; 3. with Ada.Text_IO; 4. procedure IEEE_Conversions is 5. package FIO renames Ada.Float_Text_IO; 6. package LIO renames Ada.Long_Long_Float_Text_IO; 7. use Ada.Text_IO; 8. One : Long_Float := 1.0; 9. Zero : Long_Float := 0.0; 10. Infinity : Long_Float := One / Zero; 11. NaN : Long_Float := Zero / Zero; 12. begin 13. Put ("Float infinity: "); 14. FIO.Put (Float (Infinity)); 15. New_Line; 16. Put ("Long_Long_Float infinity: "); 17. LIO.Put (Long_Long_Float (Infinity)); 18. New_Line; 19. Put ("Float NaN: "); 20. FIO.Put (Float (NaN)); 21. New_Line; 22. Put ("Long_Long_Float NaN: "); 23. LIO.Put (Long_Long_Float (NaN)); 24. New_Line; 25. end; should generate the output: Float infinity: +Inf******** Long_Long_Float infinity: +Inf******************** Float NaN: NaN********* Long_Long_Float NaN: NaN********************* Before this change, a constraint error was raised Tested on x86_64-pc-linux-gnu, committed on trunk 2014-07-31 Robert Dewar <de...@adacore.com> * checks.ads, checks.adb (Activate_Overflow_Check): Do not set flag for unconstrained fpt ops.
Index: checks.adb =================================================================== --- checks.adb (revision 213335) +++ checks.adb (working copy) @@ -389,10 +389,31 @@ procedure Activate_Overflow_Check (N : Node_Id) is begin - if not Nkind_In (N, N_Op_Rem, N_Op_Mod, N_Op_Plus) then - Set_Do_Overflow_Check (N, True); - Possible_Local_Raise (N, Standard_Constraint_Error); + -- Nothing to do for unconstrained floating-point types (the test for + -- Etype (N) being present seems necessary in some cases, should be + -- tracked down, but for now just ignore the check in this case ???) + + 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; + + -- Nothing to do for Rem/Mod/Plus (overflow not possible) + + if Nkind_In (N, N_Op_Rem, N_Op_Mod, N_Op_Plus) then + return; + end if; + + -- Otherwise set the flag + + Set_Do_Overflow_Check (N, True); + Possible_Local_Raise (N, Standard_Constraint_Error); end Activate_Overflow_Check; -------------------------- Index: checks.ads =================================================================== --- checks.ads (revision 213292) +++ checks.ads (working copy) @@ -146,7 +146,9 @@ -- Always call this routine rather than calling Set_Do_Overflow_Check to -- set an explicit value of True, to ensure handling the local raise case. -- Note that this call has no effect for MOD, REM, and unary "+" for which - -- overflow is never possible in any case. + -- overflow is never possible in any case. In addition, we do not set the + -- flag for unconstrained floating-point type operations, since we want to + -- allow for the generation of IEEE infinities in such cases. procedure Activate_Range_Check (N : Node_Id); pragma Inline (Activate_Range_Check);