[Ada] Reject numeric literals with too big exponents
authorEtienne Servais <servais@adacore.com>
Tue, 18 Jan 2022 14:45:40 +0000 (15:45 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 10 May 2022 08:19:22 +0000 (08:19 +0000)
While the compiler can compute numeric literal with arbitrary large
exponents, this may take ages and is most likely a typo. Better emit an
error when we certainly expect it to take long. The chosen threshold
takes about 100s to compute.

gcc/ada/

* scng.adb (Nlit): Error on big UI_Scale.

gcc/ada/scng.adb

index d0fb7f1..676a4f2 100644 (file)
@@ -772,6 +772,15 @@ package body Scng is
             if UI_Scale = 0 then
                Int_Literal_Value := UI_Num_Value;
 
+            --  When the exponent is large, computing is expected to take a
+            --  rather unreasonable time. We generate an error so that it
+            --  does not appear that the compiler has gotten stuck. Such a
+            --  large exponent is most likely a typo anyway.
+
+            elsif UI_Scale >= 800_000 then
+               Error_Msg_SC ("exponent too large");
+               Int_Literal_Value := No_Uint;
+
             --  Avoid doing possibly expensive calculations in cases like
             --  parsing 163E800_000# when semantics will not be done anyway.
             --  This is especially useful when parsing garbled input.