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-1478] [Ada] Avoid unhelpful dead code warnings Date: Tue, 15 Jun 2021 10:23:04 +0000 (GMT) [thread overview] Message-ID: <20210615102304.2EDE83840027@sourceware.org> (raw) https://gcc.gnu.org/g:ba998f6407ba006a8f8055171ee8e8510f0bc46b commit r12-1478-gba998f6407ba006a8f8055171ee8e8510f0bc46b Author: Steve Baird <baird@adacore.com> Date: Fri Feb 12 16:34:04 2021 -0800 [Ada] Avoid unhelpful dead code warnings gcc/ada/ * exp_util.adb (Kill_Dead_Code): Generalize the existing handling of if statements to handle case statements similarly. Diff: --- gcc/ada/exp_util.adb | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 78797f64165..860525d12a1 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -9238,28 +9238,33 @@ package body Exp_Util is if W then -- We suppress the warning if this code is under control of an - -- if statement, whose condition is a simple identifier, and - -- either we are in an instance, or warnings off is set for this - -- identifier. The reason for killing it in the instance case is - -- that it is common and reasonable for code to be deleted in - -- instances for various reasons. + -- if/case statement and either + -- a) we are in an instance and the condition/selector + -- has a statically known value; or + -- b) the condition/selector is a simple identifier and + -- warnings off is set for this identifier. + -- Dead code is common and reasonable in instances, so we don't + -- want a warning in that case. - -- Could we use Is_Statically_Unevaluated here??? + declare + C : Node_Id := Empty; + begin + if Nkind (Parent (N)) = N_If_Statement then + C := Condition (Parent (N)); + elsif Nkind (Parent (N)) = N_Case_Statement_Alternative then + C := Expression (Parent (Parent (N))); + end if; - if Nkind (Parent (N)) = N_If_Statement then - declare - C : constant Node_Id := Condition (Parent (N)); - begin - if Nkind (C) = N_Identifier - and then - (In_Instance - or else (Present (Entity (C)) - and then Has_Warnings_Off (Entity (C)))) + if Present (C) then + if (In_Instance and Compile_Time_Known_Value (C)) + or else (Nkind (C) = N_Identifier + and then Present (Entity (C)) + and then Has_Warnings_Off (Entity (C))) then W := False; end if; - end; - end if; + end if; + end; -- Generate warning if not suppressed
reply other threads:[~2021-06-15 10:23 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=20210615102304.2EDE83840027@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).