From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 4C90038346BF; Tue, 10 May 2022 08:21:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C90038346BF MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-229] [Ada] Reject numeric literals with too big exponents X-Act-Checkin: gcc X-Git-Author: Etienne Servais X-Git-Refname: refs/heads/master X-Git-Oldrev: d979a676fde85a362cb8d7b142300a494370f3e9 X-Git-Newrev: 3ad8cac47099983e9b24103e8327bc2518044877 Message-Id: <20220510082111.4C90038346BF@sourceware.org> Date: Tue, 10 May 2022 08:21:11 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 08:21:11 -0000 https://gcc.gnu.org/g:3ad8cac47099983e9b24103e8327bc2518044877 commit r13-229-g3ad8cac47099983e9b24103e8327bc2518044877 Author: Etienne Servais Date: Tue Jan 18 15:45:40 2022 +0100 [Ada] Reject numeric literals with too big exponents 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. Diff: --- gcc/ada/scng.adb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index d0fb7f1c1f6..676a4f2898c 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -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.