public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Raise Constraint_Error for Compose and Scaling if Machine_Overflows
@ 2021-05-07  9:38 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-07  9:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 314 bytes --]

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1189 bytes --]

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
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-07  9:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07  9:38 [Ada] Raise Constraint_Error for Compose and Scaling if Machine_Overflows Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).