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 r12-6317] [Ada] Warn on subtype declaration of null range Date: Thu, 6 Jan 2022 17:15:09 +0000 (GMT) [thread overview] Message-ID: <20220106171509.7E0D43858034@sourceware.org> (raw) https://gcc.gnu.org/g:2a60c08e98acaae212840b2d3329b5bd13778581 commit r12-6317-g2a60c08e98acaae212840b2d3329b5bd13778581 Author: Bob Duff <duff@adacore.com> Date: Fri Dec 10 06:01:22 2021 -0500 [Ada] Warn on subtype declaration of null range gcc/ada/ * sem_res.adb (Resolve_Range): Warn on null range, unless we are inside a generic unit or an instance thereof. * sem_ch3.adb (Analyze_Subtype_Indication): Minor: avoid double negative. Diff: --- gcc/ada/sem_ch3.adb | 8 ++++---- gcc/ada/sem_res.adb | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 7643cd16377..ce5f4536a26 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -6048,13 +6048,13 @@ package body Sem_Ch3 is begin Analyze (T); - if R /= Error then + if R = Error then + Set_Error_Posted (R); + Set_Error_Posted (T); + else Analyze (R); Set_Etype (N, Etype (R)); Resolve (R, Entity (T)); - else - Set_Error_Posted (R); - Set_Error_Posted (T); end if; end Analyze_Subtype_Indication; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 9a635068915..44b041431c8 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -10754,6 +10754,30 @@ package body Sem_Res is Fold_Uint (H, Expr_Value (H), Static => True); end if; end if; + + -- If we have a compile-time-known null range, we warn, because that is + -- likely to be a mistake. (Dynamic null ranges make sense, but often + -- compile-time-known ones do not.) Warn only if this is in a subtype + -- declaration. We do this here, rather than while analyzing a subtype + -- declaration, in case we decide to expand the cases. We do not want to + -- warn in all cases, because some are idiomatic, such as an empty + -- aggregate (1 .. 0 => <>). + + -- We don't warn in generics or their instances, because there might be + -- some instances where the range is null, and some where it is not, + -- which would lead to false alarms. + + if not (Inside_A_Generic or In_Instance) + and then Comes_From_Source (N) + and then Compile_Time_Compare + (Low_Bound (N), High_Bound (N), Assume_Valid => True) = GT + and then Nkind (Parent (N)) = N_Range_Constraint + and then Nkind (Parent (Parent (N))) = N_Subtype_Indication + and then Nkind (Parent (Parent (Parent (N)))) = N_Subtype_Declaration + and then Is_OK_Static_Range (N) + then + Error_Msg_N ("null range??", N); + end if; end Resolve_Range; --------------------------
reply other threads:[~2022-01-06 17:15 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=20220106171509.7E0D43858034@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).