From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id A8A733882010; Tue, 5 Sep 2023 11:08:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8A733882010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693912136; bh=u4AXbDlJp9FtjZ+NJ1WkDSx2jgZ24X91NbbQ/ha6tnw=; h=From:To:Subject:Date:From; b=egcc68nEtLUfJO7dDg7qEfJq7hKcKQA+xty3gmODvsM4U4y5Y3Z8qri7aeA1D7/3U Q2M5T8XehkbgWncPBcqpneIUZJhkAkszR85197+3Ynl4xSDEQlyOyY1LPP/lb4PEgy 13dDYtb5Arb7652tsZ5fIq/OrJuK05ej2HonIlYo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-3692] ada: Fix spurious warning emissions X-Act-Checkin: gcc X-Git-Author: Ronan Desplanques X-Git-Refname: refs/heads/master X-Git-Oldrev: 2f1cde4d511b9da6081b785f1c50b7e7aa271b4f X-Git-Newrev: 9be6a698f95f94a27307208cdb90bd2018182071 Message-Id: <20230905110856.A8A733882010@sourceware.org> Date: Tue, 5 Sep 2023 11:08:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9be6a698f95f94a27307208cdb90bd2018182071 commit r14-3692-g9be6a698f95f94a27307208cdb90bd2018182071 Author: Ronan Desplanques Date: Mon Aug 21 13:35:37 2023 +0200 ada: Fix spurious warning emissions Before this patch, warnings handled by `Sem_Warn.Check_References` were erroneously emitted in some cases. Here is an example of a program that, when compiled with the `-gnatwu` switch, triggered the bug: procedure Main is package T is A : Integer; end T; begin T.A := 7; end Main; The following message was emitted: main.adb:3:07: warning: variable "A" is never read and never assigned [-gnatwu] This patch mitigates the issue by restricting the cases in which `Sem_Warn.Check_References` is called for package specifications. Note that the recursive calls in `Sem_Warn.Check_References` can be used to convince oneself that this patch does not remove legitimate warnings for non-library-level package specifications. gcc/ada/ * sem_ch7.adb (Analyze_Package_Declaration): Restrict calls to `Sem_Warn.Check_References` and adjust comment accordingly. Diff: --- gcc/ada/sem_ch7.adb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index ecb4bbe3e569..1a49a53ad63b 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1267,12 +1267,17 @@ package body Sem_Ch7 is Is_Main_Unit => Parent (N) = Cunit (Main_Unit)); end if; - -- Warn about references to unset objects, which is straightforward - -- for packages with no bodies. For packages with bodies this is more - -- complicated, because some of the objects might be set between spec - -- and body elaboration, in nested or child packages, etc. - - Check_References (Id); + -- For package declarations at the library level, warn about + -- references to unset objects, which is straightforward for packages + -- with no bodies. For packages with bodies this is more complicated, + -- because some of the objects might be set between spec and body + -- elaboration, in nested or child packages, etc. Note that the + -- recursive calls in Check_References will handle nested package + -- specifications. + + if Is_Library_Level_Entity (Id) then + Check_References (Id); + end if; end if; -- Set Body_Required indication on the compilation unit node