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: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Tune warning about assignment just before a raise statement
Date: Thu, 25 May 2023 10:05:26 +0200	[thread overview]
Message-ID: <20230525080526.1955679-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

Tune warning about a possibly ineffective assignment to a formal
parameter that happens just before a raise statement.

The warning is now emitted for parameters of all by-copy types and not
just of scalar types (this gives more warnings), but is suppressed for
aliased parameters (this removes some spurious warnings).

gcc/ada/

	* sem_ch11.adb (Analyze_Raise_Expression): Tune warning condition.
	* libgnat/g-dirope.ads (Open): Remove a potentially inaccurate comment.
	* libgnat/g-dirope.adb (Open): Remove a potentially useless assignment;
	the Dir output parameter should be assigned a null value anyway by the
	preceding call to Free.

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

---
 gcc/ada/libgnat/g-dirope.adb | 1 -
 gcc/ada/libgnat/g-dirope.ads | 3 +--
 gcc/ada/sem_ch11.adb         | 7 ++++---
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/libgnat/g-dirope.adb b/gcc/ada/libgnat/g-dirope.adb
index 127f6ba8e80..3cebc9fe4a7 100644
--- a/gcc/ada/libgnat/g-dirope.adb
+++ b/gcc/ada/libgnat/g-dirope.adb
@@ -636,7 +636,6 @@ package body GNAT.Directory_Operations is
 
       if not Is_Open (Dir) then
          Free (Dir);
-         Dir := Null_Dir;
          raise Directory_Error;
       end if;
    end Open;
diff --git a/gcc/ada/libgnat/g-dirope.ads b/gcc/ada/libgnat/g-dirope.ads
index a3a8e4635f0..cdb99ff3267 100644
--- a/gcc/ada/libgnat/g-dirope.ads
+++ b/gcc/ada/libgnat/g-dirope.ads
@@ -210,8 +210,7 @@ package GNAT.Directory_Operations is
    procedure Open (Dir : out Dir_Type; Dir_Name : Dir_Name_Str);
    --  Opens the directory named by Dir_Name and returns a Dir_Type value
    --  that refers to this directory, and is positioned at the first entry.
-   --  Raises Directory_Error if Dir_Name cannot be accessed. In that case
-   --  Dir will be set to Null_Dir.
+   --  Raises Directory_Error if Dir_Name cannot be accessed.
 
    procedure Close (Dir : in out Dir_Type);
    --  Closes the directory stream referred to by Dir. After calling Close
diff --git a/gcc/ada/sem_ch11.adb b/gcc/ada/sem_ch11.adb
index 5471111d682..73eca7a603e 100644
--- a/gcc/ada/sem_ch11.adb
+++ b/gcc/ada/sem_ch11.adb
@@ -543,11 +543,12 @@ package body Sem_Ch11 is
             if Present (P) and then Nkind (P) = N_Assignment_Statement then
                L := Name (P);
 
-               --  Give warning for assignment to scalar formal
+               --  Give warning for assignment to by-copy formal
 
-               if Is_Scalar_Type (Etype (L))
-                 and then Is_Entity_Name (L)
+               if Is_Entity_Name (L)
                  and then Is_Formal (Entity (L))
+                 and then Is_By_Copy_Type (Etype (L))
+                 and then not Is_Aliased (Entity (L))
 
                  --  Do this only for parameters to the current subprogram.
                  --  This avoids some false positives for the nested case.
-- 
2.40.0


                 reply	other threads:[~2023-05-25  8:05 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=20230525080526.1955679-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=trojanek@adacore.com \
    /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).