public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [Ada] Fix warning about generic subprograms withed but not instantiated
Date: Thu, 12 May 2022 12:40:10 +0000	[thread overview]
Message-ID: <20220512124010.GA781101@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

The compiler should warn when a generic subprogram unit is withed but
not instantiated by the current main unit. This warning relies on flag
Is_Instantiated, which was wrongly set when the generic unit was also
withed and instantiated by some other unit.

This change merely reverts a fix done 20 years ago, which worked around
some spurious warning emitted with inlining enabled. Now the
Is_Instantiated flag is set similarly for generic subprograms and
generic packages.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* atree.adb, atree.ads: Move WITH clause from spec to body; to
	prevent new warnings stopping the bootstrap.
	* fmap.adb, fname-sf.adb, libgnat/a-direct.adb,
	libgnat/s-bignum.adb: Remove unnecessary WITH clauses; to
	prevent new warnings stopping the bootstrap.
	* sem_ch12.adb (Analyze_Subprogram_Instantiation): Only set
	Is_Instantiated flag when the instance is in the extended main
	source unit.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2586 bytes --]

diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb
--- a/gcc/ada/atree.adb
+++ b/gcc/ada/atree.adb
@@ -31,6 +31,7 @@ with Opt;            use Opt;
 with Output;         use Output;
 with Sinfo.Utils;    use Sinfo.Utils;
 with System.Storage_Elements;
+with Unchecked_Conversion;
 
 package body Atree is
 


diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads
--- a/gcc/ada/atree.ads
+++ b/gcc/ada/atree.ads
@@ -52,7 +52,6 @@ with Types;          use Types;
 with Seinfo;         use Seinfo;
 with System;         use System;
 with Table;
-with Unchecked_Conversion;
 
 package Atree is
 


diff --git a/gcc/ada/fmap.adb b/gcc/ada/fmap.adb
--- a/gcc/ada/fmap.adb
+++ b/gcc/ada/fmap.adb
@@ -34,8 +34,6 @@ pragma Warnings (Off);
 with System.OS_Lib; use System.OS_Lib;
 pragma Warnings (On);
 
-with Unchecked_Conversion;
-
 with GNAT.HTable;
 
 package body Fmap is


diff --git a/gcc/ada/fname-sf.adb b/gcc/ada/fname-sf.adb
--- a/gcc/ada/fname-sf.adb
+++ b/gcc/ada/fname-sf.adb
@@ -30,8 +30,6 @@ with Osint;         use Osint;
 with Types;         use Types;
 with System.OS_Lib; use System.OS_Lib;
 
-with Unchecked_Conversion;
-
 package body Fname.SF is
 
    ----------------------


diff --git a/gcc/ada/libgnat/a-direct.adb b/gcc/ada/libgnat/a-direct.adb
--- a/gcc/ada/libgnat/a-direct.adb
+++ b/gcc/ada/libgnat/a-direct.adb
@@ -38,7 +38,6 @@ use  Ada.Directories.Hierarchical_File_Names;
 with Ada.Strings.Fixed;
 with Ada.Strings.Maps;           use Ada.Strings.Maps;
 with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
-with Ada.Unchecked_Conversion;
 with Ada.Unchecked_Deallocation;
 
 with Interfaces.C;


diff --git a/gcc/ada/libgnat/s-bignum.adb b/gcc/ada/libgnat/s-bignum.adb
--- a/gcc/ada/libgnat/s-bignum.adb
+++ b/gcc/ada/libgnat/s-bignum.adb
@@ -29,7 +29,6 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Ada.Unchecked_Conversion;
 with System.Generic_Bignums;
 with System.Secondary_Stack;  use System.Secondary_Stack;
 with System.Shared_Bignums;   use System.Shared_Bignums;


diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -5708,9 +5708,9 @@ package body Sem_Ch12 is
          Set_Scope (Inst_Id, Current_Scope);
 
          Set_Entity (Gen_Id, Gen_Unit);
-         Set_Is_Instantiated (Gen_Unit);
 
          if In_Extended_Main_Source_Unit (N) then
+            Set_Is_Instantiated (Gen_Unit);
             Generate_Reference (Gen_Unit, N);
          end if;
 



                 reply	other threads:[~2022-05-12 12: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=20220512124010.GA781101@adacore.com \
    --to=derodat@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).