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: Cleanup detection of code within generic instances
Date: Mon,  7 Nov 2022 09:40:26 +0100	[thread overview]
Message-ID: <20221107084026.151175-1-poulhies@adacore.com> (raw)

From: Piotr Trojanek <trojanek@adacore.com>

To check if a node is located in a generic instance we can either look
at Instantiation_Location or at the Instantiation_Depth, but just
looking at the location is simpler and more efficient.

Cleanup related to improved detection of references to uninitialized
objects; semantics is unaffected.

gcc/ada/

	* sem_ch13.adb (Add_Call): Just look at Instantiation_Depth.
	* sem_ch3.adb (Derive_Subprograms): Likewise.
	* sem_warn.adb (Check_References): Remove redundant filtering with
	Instantiation_Depth that follows filtering with
	Instantiation_Location.
	* sinput.adb (Instantiation_Depth): Reuse Instantiation_Location.

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

---
 gcc/ada/sem_ch13.adb | 2 +-
 gcc/ada/sem_ch3.adb  | 6 +++---
 gcc/ada/sem_warn.adb | 1 -
 gcc/ada/sinput.adb   | 4 +---
 4 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 2eb1a69e764..5507353136b 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -9930,7 +9930,7 @@ package body Sem_Ch13 is
 
             if Opt.List_Inherited_Aspects
               and then not Is_Generic_Actual_Type (Typ)
-              and then Instantiation_Depth (Sloc (Typ)) = 0
+              and then Instantiation_Location (Sloc (Typ)) = No_Location
               and then not Is_Internal_Name (Chars (T))
               and then not Is_Internal_Name (Chars (Typ))
             then
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 90af32091e9..76dc6325060 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -16720,9 +16720,9 @@ package body Sem_Ch3 is
                        (Is_Generic_Unit
                           (Scope (Find_Dispatching_Type (Alias_Subp)))
                          or else
-                           Instantiation_Depth
-                             (Sloc (Find_Dispatching_Type (Alias_Subp))) > 0);
-
+                           Instantiation_Location
+                             (Sloc (Find_Dispatching_Type (Alias_Subp)))
+                               /= No_Location);
                      declare
                         Iface_Prim_Loc : constant Source_Ptr :=
                                          Original_Location (Sloc (Alias_Subp));
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 1bfa8449ad7..a1a59a8857b 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1720,7 +1720,6 @@ package body Sem_Warn is
             elsif Is_Generic_Subprogram (E1)
               and then not Is_Instantiated (E1)
               and then not Publicly_Referenceable (E1)
-              and then Instantiation_Depth (Sloc (E1)) = 0
               and then Warn_On_Redundant_Constructs
             then
                if not Warnings_Off_E1 and then not Has_Junk_Name (E1) then
diff --git a/gcc/ada/sinput.adb b/gcc/ada/sinput.adb
index 8e80213e314..c96049b2678 100644
--- a/gcc/ada/sinput.adb
+++ b/gcc/ada/sinput.adb
@@ -620,7 +620,6 @@ package body Sinput is
    -------------------------
 
    function Instantiation_Depth (S : Source_Ptr) return Nat is
-      Sind  : Source_File_Index;
       Sval  : Source_Ptr;
       Depth : Nat;
 
@@ -629,8 +628,7 @@ package body Sinput is
       Depth := 0;
 
       loop
-         Sind := Get_Source_File_Index (Sval);
-         Sval := Instantiation (Sind);
+         Sval := Instantiation_Location (Sval);
          exit when Sval = No_Location;
          Depth := Depth + 1;
       end loop;
-- 
2.34.1


                 reply	other threads:[~2022-11-07  8:40 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=20221107084026.151175-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).