From patchwork Fri Oct 23 08:26:40 2020 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: 1386579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4CHcmX3mvfz9sSG for ; Fri, 23 Oct 2020 19:27:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D5C63987951; Fri, 23 Oct 2020 08:27:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 0B0A039878DB for ; Fri, 23 Oct 2020 08:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0B0A039878DB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 36D9E117E47; Fri, 23 Oct 2020 04:26:40 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id KBkIu0ESkoO5; Fri, 23 Oct 2020 04:26:40 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 1778A117E25; Fri, 23 Oct 2020 04:26:40 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 1693E10B; Fri, 23 Oct 2020 04:26:40 -0400 (EDT) Date: Fri, 23 Oct 2020 04:26:40 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Missing detection of unused with_clause Message-ID: <20201023082640.GA127556@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Arnaud Charlet Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In some cases involving a package spec using object.method notation in e.g. subprogram aspects, an old change in Complete_Object_Operation would disable the proper detection of an unused "with" clause. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Complete_Object_Operation): Only mark entities referenced if we are compiling the extended main unit. * sem_attr.adb (Analyze_Attribute [Attribute_Tag]): Record a reference on the type and its scope. diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -6288,6 +6288,15 @@ package body Sem_Attr is if Comes_From_Source (N) then Check_Not_Incomplete_Type; + + -- 'Tag requires visibility on the corresponding package holding + -- the tag, so record a reference here, to avoid spurious unused + -- with_clause reported when compiling the main unit. + + if In_Extended_Main_Source_Unit (Current_Scope) then + Set_Referenced (P_Type, True); + Set_Referenced (Scope (P_Type), True); + end if; end if; -- Set appropriate type diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -9010,16 +9010,20 @@ package body Sem_Ch4 is Rewrite (First_Actual, Obj); end if; - -- The operation is obtained from the dispatch table and not by - -- visibility, and may be declared in a unit that is not explicitly - -- referenced in the source, but is nevertheless required in the - -- context of the current unit. Indicate that operation and its scope - -- are referenced, to prevent spurious and misleading warnings. If - -- the operation is overloaded, all primitives are in the same scope - -- and we can use any of them. - - Set_Referenced (Entity (Subprog), True); - Set_Referenced (Scope (Entity (Subprog)), True); + if In_Extended_Main_Source_Unit (Current_Scope) then + -- The operation is obtained from the dispatch table and not by + -- visibility, and may be declared in a unit that is not + -- explicitly referenced in the source, but is nevertheless + -- required in the context of the current unit. Indicate that + -- operation and its scope are referenced, to prevent spurious and + -- misleading warnings. If the operation is overloaded, all + -- primitives are in the same scope and we can use any of them. + -- Don't do that outside the main unit since otherwise this will + -- e.g. prevent the detection of some unused with clauses. + + Set_Referenced (Entity (Subprog), True); + Set_Referenced (Scope (Entity (Subprog)), True); + end if; Rewrite (Node_To_Replace, Call_Node);