From patchwork Thu Oct 15 09:40:02 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: 1382548 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 4CBknM063Jz9sTL for ; Thu, 15 Oct 2020 20:41:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A322394D833; Thu, 15 Oct 2020 09:40:14 +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 [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id D4D4C3947404 for ; Thu, 15 Oct 2020 09:40:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D4D4C3947404 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 72BCB56084; Thu, 15 Oct 2020 05:40:02 -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 gRNrWwsI-OBF; Thu, 15 Oct 2020 05:40:02 -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 412705608F; Thu, 15 Oct 2020 05:40:02 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 4046F121; Thu, 15 Oct 2020 05:40:02 -0400 (EDT) Date: Thu, 15 Oct 2020 05:40:02 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Spurious visibility on private with package Message-ID: <20201015094002.GA67985@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_QUOTING 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" When a generic package has a private with clause, this clause may not be properly uninstalled, causing entities to be visible that shouldn't be. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch10.adb (Install_With_Clause): Fix implementation of Ada 2005 AI-262 by taking into account generic packages. Minor reformatting. * libgnat/a-cbhase.ads, libgnat/a-cbhase.adb: Remove use clause on runtime unit spec. diff --git a/gcc/ada/libgnat/a-cbhase.adb b/gcc/ada/libgnat/a-cbhase.adb --- a/gcc/ada/libgnat/a-cbhase.adb +++ b/gcc/ada/libgnat/a-cbhase.adb @@ -42,6 +42,7 @@ with System; use type System.Address; package body Ada.Containers.Bounded_Hashed_Sets with SPARK_Mode => Off is + use Ada.Finalization; pragma Warnings (Off, "variable ""Busy*"" is not referenced"); pragma Warnings (Off, "variable ""Lock*"" is not referenced"); diff --git a/gcc/ada/libgnat/a-cbhase.ads b/gcc/ada/libgnat/a-cbhase.ads --- a/gcc/ada/libgnat/a-cbhase.ads +++ b/gcc/ada/libgnat/a-cbhase.ads @@ -36,7 +36,7 @@ with Ada.Iterator_Interfaces; private with Ada.Containers.Hash_Tables; with Ada.Containers.Helpers; private with Ada.Streams; -private with Ada.Finalization; use Ada.Finalization; +private with Ada.Finalization; generic type Element_Type is private; @@ -592,7 +592,7 @@ private No_Element : constant Cursor := (Container => null, Node => 0); - type Iterator is new Limited_Controlled and + type Iterator is new Ada.Finalization.Limited_Controlled and Set_Iterator_Interfaces.Forward_Iterator with record Container : Set_Access; 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 @@ -5303,8 +5303,9 @@ package body Sem_Ch10 is -- analyzing the private part of the package). if Private_Present (With_Clause) - and then Nkind (Unit (Parent (With_Clause))) = N_Package_Declaration - and then not (Private_With_OK) + and then Nkind (Unit (Parent (With_Clause))) + in N_Package_Declaration | N_Generic_Package_Declaration + and then not Private_With_OK then return; end if; @@ -5371,7 +5372,7 @@ package body Sem_Ch10 is Set_Is_Visible_Lib_Unit (Uname); -- If the unit is a wrapper package for a compilation unit that is - -- a subprogrm instance, indicate that the instance itself is a + -- a subprogram instance, indicate that the instance itself is a -- visible unit. This is necessary if the instance is inlined. if Is_Wrapper_Package (Uname) then @@ -6464,7 +6465,7 @@ package body Sem_Ch10 is null; elsif Nkind (Item) = N_With_Clause - and then Context_Installed (Item) + and then Context_Installed (Item) then -- Remove items from one with'ed unit @@ -6818,12 +6819,12 @@ package body Sem_Ch10 is -- In_Regular_With_Clause -- ---------------------------- - function In_Regular_With_Clause (E : Entity_Id) return Boolean - is + function In_Regular_With_Clause (E : Entity_Id) return Boolean is Item : Node_Id; begin Item := First (Context_Items (Comp_Unit)); + while Present (Item) loop if Nkind (Item) = N_With_Clause @@ -6836,6 +6837,7 @@ package body Sem_Ch10 is then return True; end if; + Next (Item); end loop;