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: Thu, 30 Nov 2023 11:19:14 +0100 [thread overview]
Message-ID: <20231130101914.3094378-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/i-cstrin.adb (Free): Rewrite code so there is only one
return, to remove Improper_Returns violation.
(Position_Of_Nul): Add pragma to exempt Improper_Returns
violation.
(To_Chars_Ptr): Likewise.
(Value): Likewise
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/libgnat/i-cstrin.adb | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/gcc/ada/libgnat/i-cstrin.adb b/gcc/ada/libgnat/i-cstrin.adb
index afbac727e31..1eb28655004 100644
--- a/gcc/ada/libgnat/i-cstrin.adb
+++ b/gcc/ada/libgnat/i-cstrin.adb
@@ -92,12 +92,10 @@ is
procedure Free (Item : in out chars_ptr) is
begin
- if Item = Null_Ptr then
- return;
+ if Item /= Null_Ptr then
+ Memory_Free (Item);
+ Item := Null_Ptr;
end if;
-
- Memory_Free (Item);
- Item := Null_Ptr;
end Free;
--------------------
@@ -187,6 +185,8 @@ is
function Position_Of_Nul (Into : char_array) return size_t is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
for J in Into'Range loop
if Into (J) = nul then
return J;
@@ -194,6 +194,8 @@ is
end loop;
return Into'Last + 1;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Position_Of_Nul;
------------
@@ -226,6 +228,8 @@ is
Nul_Check : Boolean := False) return chars_ptr
is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
if Item = null then
return Null_Ptr;
elsif Nul_Check
@@ -235,6 +239,8 @@ is
else
return To_chars_ptr (Item (Item'First)'Address);
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end To_Chars_Ptr;
------------
@@ -302,6 +308,8 @@ is
Length : size_t) return char_array
is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
if Item = Null_Ptr then
raise Dereference_Error;
end if;
@@ -328,6 +336,8 @@ is
return Result;
end;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Value;
function Value (Item : chars_ptr) return String is
@@ -339,6 +349,8 @@ is
Result : char_array (0 .. Length);
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
-- As per AI-00177, this is equivalent to:
-- To_Ada (Value (Item, Length) & nul);
@@ -357,6 +369,8 @@ is
Result (Length) := nul;
return To_Ada (Result);
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Value;
end Interfaces.C.Strings;
--
2.42.0
next reply other threads:[~2023-11-30 10:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 10:19 Marc Poulhiès [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-12-19 14:31 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=20231130101914.3094378-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).