From patchwork Tue Jul 12 12:25:36 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: 1655395 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=whQt2GA+; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj0XR6LGHz9sB4 for ; Tue, 12 Jul 2022 22:33:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C9D5396CA80 for ; Tue, 12 Jul 2022 12:32:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C9D5396CA80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657629163; bh=bMYxjKxpxZwkXwHosc0rLiRY+PEmuVGtBkk0Wjb+s7s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=whQt2GA+LgbC5fxwegJmgDAGv+69nqSr2IvihdadwAHudUoiRFFwfwDFlezzs8H/F kS8JmrrYinQuEIqf5/GUrmXYen4KUibR4EuwAV6YDZCdGrRb3AqL5eEwn0aApid4Xh vHh0cPN3vIuT+1U+OjDN+3OflPiWf91OKC5MQtCs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 227F73856949 for ; Tue, 12 Jul 2022 12:25:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 227F73856949 Received: by mail-ed1-x52c.google.com with SMTP id y8so9891140eda.3 for ; Tue, 12 Jul 2022 05:25:38 -0700 (PDT) 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=bMYxjKxpxZwkXwHosc0rLiRY+PEmuVGtBkk0Wjb+s7s=; b=RSr/k6hk8/IyKVoviDrx53ObASz8W7bEPBbqXysptNjb8DaAcLi+2FgFSS5em6KG1H AT/84+6d+ChQJnj2zr+/0piSyo3tUI1dHPzEpaZI/FpuSzmZWU/ipyHKUec+bZVYF3DM uV+BPU0YKvKH90c4RllHC9+iVSpFDgES0PAJ8KzNLcIVIVJJN8a/YyGicJbORprqL27N xgloyQw84tDP+YL0B8K6fuDxnJf3qiWC2soFwz0WRNHvuzL7TeSe9DMeM90Ffj1XZSKs nXqh529QzcVQv0t0NXJpnVqAkJS46KnejUovFppOXDWnMzVJKRjMp9LToIrqLGIJGvcx pOQg== X-Gm-Message-State: AJIora9+ytJeYfAlSbw97a63CmFVqjZ1V/q1+j5kCEp9VJCc6BB96NFF /8W8patrqPvg9ELpwwgUB8jmuC1org1Oww== X-Google-Smtp-Source: AGRyM1sWf1ULkDUPc6Crwaae80wfknDt6hfqFxEN9VDqkZRJvM/5WHXTSMw4hIpwZkSnTUs3WIw8VQ== X-Received: by 2002:a05:6402:428a:b0:42e:8f7e:1638 with SMTP id g10-20020a056402428a00b0042e8f7e1638mr31900602edc.228.1657628737701; Tue, 12 Jul 2022 05:25:37 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id d26-20020a170906345a00b00726e51b6d7dsm3725195ejb.195.2022.07.12.05.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 05:25:37 -0700 (PDT) Date: Tue, 12 Jul 2022 12:25:36 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Spurious use_type clause warning Message-ID: <20220712122536.GA3404993@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch corrects an error in the compiler whereby a spurious redundant use_type_clause warning gets issued when the clause appears in the context_clause of a package preceding a with_clause for a package with an identical use_clause in its specification. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * einfo.ads: Modify documentation for In_Use flag to include scope stack manipulation. * sem_ch8.adb (Use_One_Type): Add condition to return when attempting to detect redundant use_type_clauses in child units in certain cases. diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -2309,6 +2309,10 @@ package Einfo is -- the corresponding entity. Reset at end of corresponding declarative -- part. The flag on a type is also used to determine the visibility of -- the primitive operators of the type. +-- +-- Note that manipulation of scopes on the scope stack will also cause +-- the flag to be set/unset since the setting of scopes affects +-- visibility. -- Is_Abstract_Subprogram -- Defined in all subprograms and entries. Set for abstract subprograms. diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -10758,15 +10758,26 @@ package body Sem_Ch8 is return; end if; - -- There is a redundant use_type_clause in a child unit. - -- Determine which of the units is more deeply nested. If a + -- If there is a redundant use_type_clause in a child unit + -- determine which of the units is more deeply nested. If a -- unit is a package instance, retrieve the entity and its -- scope from the instance spec. Ent1 := Entity_Of_Unit (Unit1); Ent2 := Entity_Of_Unit (Unit2); - if Scope (Ent2) = Standard_Standard then + -- When the scope of both units' entities are + -- Standard_Standard then neither Unit1 or Unit2 are child + -- units - so return in that case. + + if Scope (Ent1) = Standard_Standard + and then Scope (Ent2) = Standard_Standard + then + return; + + -- Otherwise, determine if one of the units is not a child + + elsif Scope (Ent2) = Standard_Standard then Error_Msg_Sloc := Sloc (Clause2); Err_No := Clause1;