public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-229] [Ada] Reject numeric literals with too big exponents Date: Tue, 10 May 2022 08:21:11 +0000 (GMT) [thread overview] Message-ID: <20220510082111.4C90038346BF@sourceware.org> (raw) https://gcc.gnu.org/g:3ad8cac47099983e9b24103e8327bc2518044877 commit r13-229-g3ad8cac47099983e9b24103e8327bc2518044877 Author: Etienne Servais <servais@adacore.com> 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.
reply other threads:[~2022-05-10 8:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220510082111.4C90038346BF@sourceware.org \ --to=pmderodat@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).