From patchwork Fri Jan 7 16:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1576688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CdgeYNaf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVpb737LCz9t25 for ; Sat, 8 Jan 2022 03:29:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C2743857C76 for ; Fri, 7 Jan 2022 16:29:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C2743857C76 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641572977; bh=sLrLFOYzFL321DWQ2ifYgGgQpA8/8H0gYoIMmTPG6oc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CdgeYNafdXNSY9GJnMgAhKFfmSF41ywaemNY0cNkCQLoffnOQ/7qtPilaYaBEYn3m AFXnNWrzxMnO8mOtlEKMOak77YvMo72MsKor9mJuZPpujzdQ7zLcS01JDCc0xfaHAU Iv0h9jupci4dK8FisY2W7EJu6sw96XjRiJZpfeno= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 1E8A53858412 for ; Fri, 7 Jan 2022 16:26:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E8A53858412 Received: by mail-wr1-x42f.google.com with SMTP id s1so12068289wra.6 for ; Fri, 07 Jan 2022 08:26:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=sLrLFOYzFL321DWQ2ifYgGgQpA8/8H0gYoIMmTPG6oc=; b=6Fyxw18FOQUeZwWUvAYB+lxZNgfAa/ttSoqFk9vsptX12HL6/k45SBtvVq3Jpm6G8r TERqmF5LsXDCheMx53kTYuYdaYKb9xcjFilsu+Pk7aMIKeF6QxAtexDJqr/iZm0l/4f6 JDBNXW2cDHL8RA1WIMTe594IK1OlD/uWugIfxJroNC0f+gqlysrRSUyMGjSPi6/0FjvX n0Vc+fUbJxAPnsMz4zPwaY3NQOZlntww0Qdsb16OfEnNoR/XWz3C2GZVHSpDVrIwxecY mUAvnw03RIOCcaUHw7q7gd1oqWic5CFslXL4L9uip9U+G9D8ycZ3e3xcAzWLUrPu6QcF gUwA== X-Gm-Message-State: AOAM530aF17osdiuERXXbLRCU/fNv2r2TGwyG5L3kSAmy4TuDzEiHVkY YmnF/rddMcmmOZmZfPGIB4txIpHmQBrxhQ== X-Google-Smtp-Source: ABdhPJwpVQM3Auk+LNKw7qWb06X3j/Z/V2vWBHGhjjNnEi5QorLCE8w2dj6fS4cb5PHCPoUWrxJhMA== X-Received: by 2002:adf:f4c6:: with SMTP id h6mr9485906wrp.341.1641572816125; Fri, 07 Jan 2022 08:26:56 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u10sm5357960wrs.28.2022.01.07.08.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 08:26:55 -0800 (PST) Date: Fri, 7 Jan 2022 16:26:55 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Warn on import of parent package Message-ID: <20220107162655.GA948031@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Bob Duff Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" There is no need to say "with P;" in package P.Q. This patch adds a warning for that case. We also remove with clauses in our own code that trigger the warning. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch10.adb (Check_Redundant_Withs): Add a warning if a library unit with's its own ancestor. Note that this warning is not triggered for something like "with P.R;" in P.Q, because there the "with P;" is considered implicit. * fname-sf.adb, libgnarl/s-stusta.adb, libgnarl/s-tasdeb.ads, libgnat/a-calfor.adb, libgnat/a-tiboio.adb, libgnat/a-wwboio.adb, libgnat/a-zzboio.adb, libgnat/i-cobol.adb, libgnat/s-bitops.adb, libgnat/s-bitops.ads, libgnat/s-direio.adb, libgnat/s-dwalin.adb, libgnat/s-geveop.adb, libgnat/s-mmosin__unix.adb, libgnat/s-os_lib.adb, libgnat/s-os_lib.ads, libgnat/s-pooglo.ads, libgnat/s-secsta.adb, libgnat/s-shasto.adb, libgnat/s-stausa.ads, libgnat/s-stratt.ads, libgnat/s-ststop.adb: Remove with of parent. * sinfo.ads: Minor comment fix. 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 @@ -24,7 +24,6 @@ ------------------------------------------------------------------------------ with Casing; use Casing; -with Fname; use Fname; with Fname.UF; use Fname.UF; with SFN_Scan; use SFN_Scan; with Osint; use Osint; diff --git a/gcc/ada/libgnarl/s-stusta.adb b/gcc/ada/libgnarl/s-stusta.adb --- a/gcc/ada/libgnarl/s-stusta.adb +++ b/gcc/ada/libgnarl/s-stusta.adb @@ -29,8 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with System.Stack_Usage; - -- This is why this package is part of GNARL: with System.Tasking.Debug; diff --git a/gcc/ada/libgnarl/s-tasdeb.ads b/gcc/ada/libgnarl/s-tasdeb.ads --- a/gcc/ada/libgnarl/s-tasdeb.ads +++ b/gcc/ada/libgnarl/s-tasdeb.ads @@ -32,7 +32,6 @@ -- This package encapsulates all direct interfaces to task debugging services -- that are needed by gdb with gnat mode. -with System.Tasking; with System.OS_Interface; package System.Tasking.Debug is diff --git a/gcc/ada/libgnat/a-calfor.adb b/gcc/ada/libgnat/a-calfor.adb --- a/gcc/ada/libgnat/a-calfor.adb +++ b/gcc/ada/libgnat/a-calfor.adb @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with Ada.Calendar; use Ada.Calendar; with Ada.Calendar.Time_Zones; use Ada.Calendar.Time_Zones; package body Ada.Calendar.Formatting is diff --git a/gcc/ada/libgnat/a-tiboio.adb b/gcc/ada/libgnat/a-tiboio.adb --- a/gcc/ada/libgnat/a-tiboio.adb +++ b/gcc/ada/libgnat/a-tiboio.adb @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Deallocation; package body Ada.Text_IO.Bounded_IO is diff --git a/gcc/ada/libgnat/a-wwboio.adb b/gcc/ada/libgnat/a-wwboio.adb --- a/gcc/ada/libgnat/a-wwboio.adb +++ b/gcc/ada/libgnat/a-wwboio.adb @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with Ada.Wide_Text_IO; use Ada.Wide_Text_IO; with Ada.Unchecked_Deallocation; package body Ada.Wide_Text_IO.Wide_Bounded_IO is diff --git a/gcc/ada/libgnat/a-zzboio.adb b/gcc/ada/libgnat/a-zzboio.adb --- a/gcc/ada/libgnat/a-zzboio.adb +++ b/gcc/ada/libgnat/a-zzboio.adb @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO; with Ada.Unchecked_Deallocation; package body Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO is diff --git a/gcc/ada/libgnat/i-cobol.adb b/gcc/ada/libgnat/i-cobol.adb --- a/gcc/ada/libgnat/i-cobol.adb +++ b/gcc/ada/libgnat/i-cobol.adb @@ -34,8 +34,7 @@ -- particular COBOL format is completely contained in the private part of -- the spec. -with Interfaces; use Interfaces; -with System; use System; +with System; use System; with Ada.Unchecked_Conversion; package body Interfaces.COBOL is diff --git a/gcc/ada/libgnat/s-bitops.adb b/gcc/ada/libgnat/s-bitops.adb --- a/gcc/ada/libgnat/s-bitops.adb +++ b/gcc/ada/libgnat/s-bitops.adb @@ -29,8 +29,7 @@ -- -- ------------------------------------------------------------------------------ -with System; use System; -with System.Unsigned_Types; use System.Unsigned_Types; +with System.Unsigned_Types; use System.Unsigned_Types; with Ada.Exceptions; use Ada.Exceptions; with Ada.Unchecked_Conversion; diff --git a/gcc/ada/libgnat/s-bitops.ads b/gcc/ada/libgnat/s-bitops.ads --- a/gcc/ada/libgnat/s-bitops.ads +++ b/gcc/ada/libgnat/s-bitops.ads @@ -31,8 +31,6 @@ -- Operations on packed bit strings -with System; - package System.Bit_Ops is -- Note: in all the following routines, the System.Address parameters diff --git a/gcc/ada/libgnat/s-direio.adb b/gcc/ada/libgnat/s-direio.adb --- a/gcc/ada/libgnat/s-direio.adb +++ b/gcc/ada/libgnat/s-direio.adb @@ -32,7 +32,6 @@ with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Ada.Unchecked_Deallocation; with Interfaces.C_Streams; use Interfaces.C_Streams; -with System; use System; with System.CRTL; with System.File_IO; with System.Soft_Links; diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb --- a/gcc/ada/libgnat/s-dwalin.adb +++ b/gcc/ada/libgnat/s-dwalin.adb @@ -35,7 +35,6 @@ with Ada.Unchecked_Deallocation; with Interfaces; use Interfaces; -with System; use System; with System.Address_Image; with System.Bounded_Strings; use System.Bounded_Strings; with System.IO; use System.IO; diff --git a/gcc/ada/libgnat/s-geveop.adb b/gcc/ada/libgnat/s-geveop.adb --- a/gcc/ada/libgnat/s-geveop.adb +++ b/gcc/ada/libgnat/s-geveop.adb @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with System; use System; with System.Address_Operations; use System.Address_Operations; with System.Storage_Elements; use System.Storage_Elements; diff --git a/gcc/ada/libgnat/s-mmosin__unix.adb b/gcc/ada/libgnat/s-mmosin__unix.adb --- a/gcc/ada/libgnat/s-mmosin__unix.adb +++ b/gcc/ada/libgnat/s-mmosin__unix.adb @@ -30,7 +30,6 @@ ------------------------------------------------------------------------------ with Ada.IO_Exceptions; -with System; use System; with System.OS_Lib; use System.OS_Lib; with System.Mmap.Unix; use System.Mmap.Unix; diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb --- a/gcc/ada/libgnat/s-os_lib.adb +++ b/gcc/ada/libgnat/s-os_lib.adb @@ -31,7 +31,6 @@ with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; -with System; use System; with System.Case_Util; with System.CRTL; with System.Soft_Links; diff --git a/gcc/ada/libgnat/s-os_lib.ads b/gcc/ada/libgnat/s-os_lib.ads --- a/gcc/ada/libgnat/s-os_lib.ads +++ b/gcc/ada/libgnat/s-os_lib.ads @@ -48,7 +48,6 @@ -- be used by other predefined packages. User access to this package is via -- a renaming of this package in GNAT.OS_Lib (file g-os_lib.ads). -with System; with System.Strings; package System.OS_Lib is diff --git a/gcc/ada/libgnat/s-pooglo.ads b/gcc/ada/libgnat/s-pooglo.ads --- a/gcc/ada/libgnat/s-pooglo.ads +++ b/gcc/ada/libgnat/s-pooglo.ads @@ -32,7 +32,6 @@ -- Storage pool corresponding to default global storage pool used for types -- for which no storage pool is specified. -with System; with System.Storage_Pools; with System.Storage_Elements; diff --git a/gcc/ada/libgnat/s-secsta.adb b/gcc/ada/libgnat/s-secsta.adb --- a/gcc/ada/libgnat/s-secsta.adb +++ b/gcc/ada/libgnat/s-secsta.adb @@ -32,7 +32,6 @@ with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; -with System; use System; with System.Parameters; use System.Parameters; with System.Soft_Links; use System.Soft_Links; with System.Storage_Elements; use System.Storage_Elements; diff --git a/gcc/ada/libgnat/s-shasto.adb b/gcc/ada/libgnat/s-shasto.adb --- a/gcc/ada/libgnat/s-shasto.adb +++ b/gcc/ada/libgnat/s-shasto.adb @@ -36,7 +36,6 @@ with Ada.Streams.Stream_IO; with System.Global_Locks; with System.Soft_Links; -with System; with System.CRTL; with System.File_Control_Block; with System.File_IO; diff --git a/gcc/ada/libgnat/s-stausa.ads b/gcc/ada/libgnat/s-stausa.ads --- a/gcc/ada/libgnat/s-stausa.ads +++ b/gcc/ada/libgnat/s-stausa.ads @@ -29,7 +29,6 @@ -- -- ------------------------------------------------------------------------------ -with System; with System.Storage_Elements; with System.Address_To_Access_Conversions; with Interfaces; diff --git a/gcc/ada/libgnat/s-stratt.ads b/gcc/ada/libgnat/s-stratt.ads --- a/gcc/ada/libgnat/s-stratt.ads +++ b/gcc/ada/libgnat/s-stratt.ads @@ -37,7 +37,6 @@ -- defined types, the subprogram for the corresponding root type is called -- with an appropriate conversion. -with System; with System.Unsigned_Types; with Ada.Streams; diff --git a/gcc/ada/libgnat/s-ststop.adb b/gcc/ada/libgnat/s-ststop.adb --- a/gcc/ada/libgnat/s-ststop.adb +++ b/gcc/ada/libgnat/s-ststop.adb @@ -33,7 +33,6 @@ with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Ada.Streams; use Ada.Streams; with Ada.Unchecked_Conversion; -with System; use System; with System.Storage_Elements; use System.Storage_Elements; with System.Stream_Attributes; diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -268,6 +268,8 @@ package body Sem_Ch10 is ------------------------------ procedure Analyze_Compilation_Unit (N : Node_Id) is + Unit_Node : constant Node_Id := Unit (N); + procedure Check_Redundant_Withs (Context_Items : List_Id; Spec_Context_Items : List_Id := No_List); @@ -587,6 +589,13 @@ package body Sem_Ch10 is -- Standalone package spec or body check else + if Is_Ancestor_Package (Entity (Name (Clause)), + Defining_Entity (Unit_Node)) + then + Error_Msg_N + ("unnecessary with of ancestor?r?", Clause); + end if; + declare Dummy : Boolean := False; Withed : Boolean := False; @@ -617,7 +626,6 @@ package body Sem_Ch10 is -- Local variables Main_Cunit : constant Node_Id := Cunit (Main_Unit); - Unit_Node : constant Node_Id := Unit (N); Lib_Unit : Node_Id := Library_Unit (N); Par_Spec_Name : Unit_Name_Type; Spec_Id : Entity_Id; diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -200,7 +200,7 @@ package Sinfo is -- The exceptions to this rule occur with {DEFINING_IDENTIFIERS} in all -- contexts, which is handled as described in the previous section, and - -- with {,library_unit_NAME} in the N_With_Clause mode, which is handled + -- with {,library_unit_NAME} in the N_With_Clause node, which is handled -- using the First_Name and Last_Name flags, as further detailed in the -- description of the N_With_Clause node.