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-6233] [Ada] Prevent Get_Current_Value_Condition from returning the same node Date: Wed, 5 Jan 2022 11:34:07 +0000 (GMT) [thread overview] Message-ID: <20220105113407.DA3D7385842E@sourceware.org> (raw) https://gcc.gnu.org/g:a6505936a35e7a5c66e36f7c4e2032c5c7f64838 commit r12-6233-ga6505936a35e7a5c66e36f7c4e2032c5c7f64838 Author: Bob Duff <duff@adacore.com> Date: Tue Nov 30 16:00:40 2021 -0500 [Ada] Prevent Get_Current_Value_Condition from returning the same node gcc/ada/ * exp_util.ads (Get_Current_Value_Condition): Belt: Add a postcondition that Val /= Var. * sem_util.adb (Known_Null): Suspenders: Raise Program_Error if Get_Current_Value_Condition returned the same value. This will be enabled even without assertions, because infinite recursion is a nuisance -- better to crash if this bug ever occurs. Diff: --- gcc/ada/exp_util.ads | 2 +- gcc/ada/sem_util.adb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads index 2b61132107c..773fa01e871 100644 --- a/gcc/ada/exp_util.ads +++ b/gcc/ada/exp_util.ads @@ -703,7 +703,7 @@ package Exp_Util is procedure Get_Current_Value_Condition (Var : Node_Id; Op : out Node_Kind; - Val : out Node_Id); + Val : out Node_Id) with Post => Val /= Var; -- This routine processes the Current_Value field of the variable Var. If -- the Current_Value field is null or if it represents a known value, then -- on return Cond is set to N_Empty, and Val is set to Empty. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 49a58e3c615..7064dfac8d8 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -22062,6 +22062,13 @@ package body Sem_Util is Get_Current_Value_Condition (N, Op, Val); + -- If Get_Current_Value_Condition were to return Val = N, then the + -- recursion below could be infinite. + + if Val = N then + raise Program_Error; + end if; + if Known_Null (Val) then if Op = N_Op_Eq then return True;
reply other threads:[~2022-01-05 11:34 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=20220105113407.DA3D7385842E@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).