diff mbox series

[Ada] Raise Constraint_Error for Compose and Scaling if Machine_Overflows

Message ID 20210507093822.GA140595@adacore.com
State New
Headers show
Series [Ada] Raise Constraint_Error for Compose and Scaling if Machine_Overflows | expand

Commit Message

Pierre-Marie de Rodat May 7, 2021, 9:38 a.m. UTC
This is an optional behavior specified by the RM and it makes sense to
do it when T'Machine_Overflows is True for the sake of consistency.

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

gcc/ada/

	* libgnat/s-fatgen.adb (Scaling): Raise Constraint_Error in the
	overflow case when T'Machine_Overflows is True.
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/s-fatgen.adb b/gcc/ada/libgnat/s-fatgen.adb
--- a/gcc/ada/libgnat/s-fatgen.adb
+++ b/gcc/ada/libgnat/s-fatgen.adb
@@ -771,12 +771,19 @@  package body System.Fat_Gen is
          --  Check for overflow
 
          if Adjustment > IEEE_Emax - Exp then
-            XX := 0.0;
-            return (if Minus then -1.0 / XX else 1.0 / XX);
-            pragma Annotate
-              (CodePeer, Intentional, "overflow check", "Infinity produced");
-            pragma Annotate
-              (CodePeer, Intentional, "divide by zero", "Infinity produced");
+            --  Optionally raise Constraint_Error as per RM A.5.3(29)
+
+            if T'Machine_Overflows then
+               raise Constraint_Error with "Too large exponent";
+
+            else
+               XX := 0.0;
+               return (if Minus then -1.0 / XX else 1.0 / XX);
+               pragma Annotate (CodePeer, Intentional, "overflow check",
+                                "Infinity produced");
+               pragma Annotate (CodePeer, Intentional, "divide by zero",
+                                "Infinity produced");
+            end if;
 
          --  Check for underflow