public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Sheri Bernstein <bernstein@adacore.com>
Subject: [COMMITTED] ada: Remove GNATcheck violations
Date: Tue, 19 Dec 2023 15:31:03 +0100	[thread overview]
Message-ID: <20231219143103.455945-1-poulhies@adacore.com> (raw)

From: Sheri Bernstein <bernstein@adacore.com>

Remove GNATcheck violations by refactoring code and also using
pragma Annotate to exempt them.

gcc/ada/

	* libgnat/a-comlin.adb (Argument_Count): Rewrite code so there is
	only one return, to remove Improper_Returns violation.
	(Command_Name): Add pragma to exempt Improper_Returns violation.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-comlin.adb | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/libgnat/a-comlin.adb b/gcc/ada/libgnat/a-comlin.adb
index b95ecd3290c..8a6686181bd 100644
--- a/gcc/ada/libgnat/a-comlin.adb
+++ b/gcc/ada/libgnat/a-comlin.adb
@@ -77,16 +77,11 @@ package body Ada.Command_Line is
 
    function Argument_Count return Natural is
    begin
-      if not Initialized then
-         --  RM A.15 (11)
-         return 0;
-      end if;
-
-      if Remove_Args = null then
-         return Arg_Count - 1;
-      else
-         return Remove_Count;
-      end if;
+      return
+         (if not Initialized then 0  --  RM A.15 (11)
+          elsif Remove_Args = null then Arg_Count - 1
+          else Remove_Count
+         );
    end Argument_Count;
 
    -----------------
@@ -107,6 +102,8 @@ package body Ada.Command_Line is
 
    function Command_Name return String is
    begin
+      pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+                       "early returns for performance");
       if not Initialized then
          return "";
       end if;
@@ -118,6 +115,7 @@ package body Ada.Command_Line is
          Fill_Arg (Arg'Address, 0);
          return Arg;
       end;
+      pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
    end Command_Name;
 
 end Ada.Command_Line;
-- 
2.43.0


             reply	other threads:[~2023-12-19 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 14:31 Marc Poulhiès [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-11-30 10:19 Marc Poulhiès
2023-09-05 11:07 Marc Poulhiès

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=20231219143103.455945-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=bernstein@adacore.com \
    --cc=gcc-patches@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: link
Be 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).