From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ronan Desplanques <desplanques@adacore.com>
Subject: [COMMITTED] ada: Tweak internal subprogram in Ada.Directories
Date: Tue, 10 Oct 2023 14:14:57 +0200 [thread overview]
Message-ID: <20231010121457.3888606-1-poulhies@adacore.com> (raw)
From: Ronan Desplanques <desplanques@adacore.com>
The purpose of this patch is to work around false-positive warnings
emitted by GNAT SAS (also known as CodePeer). It does not change
the behavior of the modified subprogram.
gcc/ada/
* libgnat/a-direct.adb (Start_Search_Internal): Tweak subprogram
body.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/libgnat/a-direct.adb | 46 ++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/gcc/ada/libgnat/a-direct.adb b/gcc/ada/libgnat/a-direct.adb
index f7a1d5dfd6d..594971c6021 100644
--- a/gcc/ada/libgnat/a-direct.adb
+++ b/gcc/ada/libgnat/a-direct.adb
@@ -1379,13 +1379,21 @@ package body Ada.Directories is
Compose (Directory, File_Name) & ASCII.NUL;
Path : String renames
Path_C (Path_C'First .. Path_C'Last - 1);
- Found : Boolean := False;
Attr : aliased File_Attributes;
Exists : Integer;
Error : Integer;
- Kind : File_Kind;
- Size : File_Size;
+ type Result (Found : Boolean := False) is record
+ case Found is
+ when True =>
+ Kind : File_Kind;
+ Size : File_Size;
+ when False =>
+ null;
+ end case;
+ end record;
+
+ Res : Result := (Found => False);
begin
-- Get the file attributes for the directory item
@@ -1416,32 +1424,28 @@ package body Ada.Directories is
if Is_Regular_File_Attr (Path_C'Address, Attr'Access) = 1
then
if Filter (Ordinary_File) then
- Found := True;
- Kind := Ordinary_File;
- Size :=
- File_Size
- (File_Length_Attr
- (-1, Path_C'Address, Attr'Access));
+ Res := (Found => True,
+ Kind => Ordinary_File,
+ Size => File_Size
+ (File_Length_Attr
+ (-1, Path_C'Address, Attr'Access)));
end if;
elsif Is_Directory_Attr (Path_C'Address, Attr'Access) = 1
then
if Filter (File_Kind'First) then
- Found := True;
- Kind := File_Kind'First;
- -- File_Kind'First is used instead of Directory due
- -- to a name overload issue with the procedure
- -- parameter Directory.
- Size := 0;
+ Res := (Found => True,
+ Kind => File_Kind'First,
+ Size => 0);
end if;
elsif Filter (Special_File) then
- Found := True;
- Kind := Special_File;
- Size := 0;
+ Res := (Found => True,
+ Kind => Special_File,
+ Size => 0);
end if;
- if Found then
+ if Res.Found then
Search.State.Dir_Contents.Append
(Directory_Entry_Type'
(Valid => True,
@@ -1449,9 +1453,9 @@ package body Ada.Directories is
To_Unbounded_String (File_Name),
Full_Name => To_Unbounded_String (Path),
Attr_Error_Code => 0,
- Kind => Kind,
+ Kind => Res.Kind,
Modification_Time => Modification_Time (Path),
- Size => Size));
+ Size => Res.Size));
end if;
end if;
end;
--
2.42.0
reply other threads:[~2023-10-10 12: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=20231010121457.3888606-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=desplanques@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).