From patchwork Thu Sep 7 09:40:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 810945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461672-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="w8+KYcjE"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xnwS92h62z9sNV for ; Thu, 7 Sep 2017 19:40:57 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=a5bVw9MUrQVeXZcdbIsC2swVzDkHk1I+sMfCxt85KbnAmF65zC deUJpl6Z99HEBUpIu//GQkajuRGS5CeK3Viyc6b2ACiQhPWu/FzZn6fCAYgdUezQ KIdowjOxAElM/7tpyW/WPwvKVctulWj5Whz469F7dWe8dNMSG6BrQ7fqc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=jv/32NQSrzXZXjBb5RNv7EshLeg=; b=w8+KYcjEGG8L0kcQIWbg eqK3mvbLy5/fnNCFirI2rijduKdTeGU5rybPoOACE+9CrgPxOtvgYMYQxCShKBT3 DbxZmM/Y034mhIPNpFFL7925ANSIKzZ75Ivc+gQ7+ULR9ukfOOO57VBR57toU0Jv RKXrmswHpYhyzhp49Zl97gg= Received: (qmail 69639 invoked by alias); 7 Sep 2017 09:40:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 69556 invoked by uid 89); 7 Sep 2017 09:40:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=declaring X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Sep 2017 09:40:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6A341561A2; Thu, 7 Sep 2017 05:40:32 -0400 (EDT) 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 JG9HSphGX5-v; Thu, 7 Sep 2017 05:40:32 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 59D2356179; Thu, 7 Sep 2017 05:40:32 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 58B834FC; Thu, 7 Sep 2017 05:40:32 -0400 (EDT) Date: Thu, 7 Sep 2017 05:40:32 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Fix internal error on package instantiation and inlining Message-ID: <20170907094032.GA93720@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This fixes a small regression introduced by the recent improvement to the algorithm used by Hide_Public_Entities to compute the final set of external visible entities of a package. Subprogram renamings not only need to be dealt with as declaring a subprogram but also as referencing another one. The following procedure must compile quietly with -O -gnatn: with Q; procedure P (I : Integer) is begin if Q.Derive (I) /= I then raise Program_Error; end if; end; with G; package Q is function Derive (I : Integer) return Integer; pragma Inline (Derive); end Q; with G; package body Q is function Value (I : Integer) return Integer is begin return I; end; package My_G is new G (Integer, Value); function Derive (I : Integer) return Integer is begin return My_G.Compute (I); end; end Q; generic type T is private; with function Value (Arg : T) return Integer; package G is function Compute (Arg : T) return Integer; pragma Inline (Compute); end G; package body G is function Compute (Arg : T) return Integer is begin return Value (Arg); end; end G; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-07 Eric Botcazou * sem_ch7.adb (Has_Referencer): For a subprogram renaming, also mark the renamed subprogram as referenced. Index: sem_ch7.adb =================================================================== --- sem_ch7.adb (revision 251835) +++ sem_ch7.adb (working copy) @@ -439,6 +439,23 @@ then Set_Is_Public (Decl_Id, False); end if; + + -- For a subprogram renaming, if the entity is referenced, + -- then so is the renamed subprogram. But there is an issue + -- with generic bodies because instantiations are not done + -- yet and, therefore, cannot be scanned for referencers. + -- That's why we use an approximation and test that we have + -- at least one subprogram referenced by an inlined body + -- instead of precisely the entity of this renaming. + + if Nkind (Decl) = N_Subprogram_Renaming_Declaration + and then Subprogram_Table.Get_First + and then Is_Entity_Name (Name (Decl)) + and then Present (Entity (Name (Decl))) + and then Is_Subprogram (Entity (Name (Decl))) + then + Subprogram_Table.Set (Entity (Name (Decl)), True); + end if; end if; Prev (Decl);