From patchwork Fri Feb 20 09:53:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 441900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 522ED140188 for ; Fri, 20 Feb 2015 20:53:46 +1100 (AEDT) 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=Z0AqhFGHK8b/6V51E+digoVHiMhz42olIG1h0Mv0olif+FlklA l/f6ZNJh8IEW1wRmjfl3RMc6V4+Ry4Nko9VvjKYghVzKk5NhGEx/Lew5LPsTl4Bx xbqBChH9c3e9b6dzo+p6f50WHOwb83aku3mvN3Qfh7oIrpAM++akq2Ms4= 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=iwvx3wInJJaLn/xcLxukasMvM8k=; b=KRnGsuPLlp+wK8kGVked jfIsE9BJ/GBq6cUidCzvScXwgKWxGt0HbCRIbOzuR2arePhUAfybbuO8oqGuEdEr i6S63YJdLgICp6iLV/7VKgS8ODMQ99Qc2SIWoi39vLRKsgFtn6Q6Gm4HqbbhYzZF C6INKhQepgcHmnJWqDxbY5M= Received: (qmail 835 invoked by alias); 20 Feb 2015 09:53:38 -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 770 invoked by uid 89); 20 Feb 2015 09:53:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 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 (AES256-SHA encrypted) ESMTPS; Fri, 20 Feb 2015 09:53:36 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id CFA511167E5; Fri, 20 Feb 2015 04:53:34 -0500 (EST) 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 5x1cvc80XaF3; Fri, 20 Feb 2015 04:53:34 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [IPv6:2620:20:4000:0:7a2b:cbff:fe60:cb11]) by rock.gnat.com (Postfix) with ESMTP id BD6261167B9; Fri, 20 Feb 2015 04:53:34 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id B750B3FE3B; Fri, 20 Feb 2015 04:53:34 -0500 (EST) Date: Fri, 20 Feb 2015 04:53:34 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Fix internal error on inlining of renamed subprogram instantiation Message-ID: <20150220095334.GA2938@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This fixes an assertion failure in gigi triggered by an order-of-elaboration issue for the type of a parameter of a subprogram which is both the renaming of another subprogram and marked Inline. In this case the compiler was using expansion (aka front-end inlining) but this doesn't always play nice with the freezing model used for generics so the patch makes it use back-end inlining. The following package must compile quietly with -O -gnatn: with F; with G; package P is function Uid_Image (Uid : Integer) return String; package Inner is type Arr is array (Positive range <>) of Integer; function Image is new F (Integer, Positive, Arr, Uid_Image); end Inner; package Value_Set is new G (Integer); function Uid_Image (Uid : Integer) return String renames Value_Set.Uid_Image; pragma Inline (Uid_Image); end P; generic type Item_T is limited private; type Index_T is (<>); type Array_T is array (Index_T range <>) of Item_T; with function Image (Item : Item_T) return String; function F (A : Array_T) return String; with Ada.Strings.Unbounded; function F (A : Array_T) return String is Result : Ada.Strings.Unbounded.Unbounded_String; begin for I in A'Range loop Ada.Strings.Unbounded.Append (Result, Image (A (I))); end loop; return Ada.Strings.Unbounded.To_String (Result); end; generic type T is range <>; package G is function Uid_Image (Uid : T) return String; end G; package body G is function Uid_Image (Uid : T) return String is begin return T'Image (Uid); end; end G; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-02-20 Eric Botcazou * inline.adb (Expand_Inlined_Call): Skip again calls to subprogram renamings. * exp_ch6.adb (Expand_Call): Use back-end inlining instead of expansion for simple subprogram renamings. Index: inline.adb =================================================================== --- inline.adb (revision 220841) +++ inline.adb (working copy) @@ -2694,12 +2694,11 @@ return; -- Skip inlining if this is not a true inlining since the attribute - -- Body_To_Inline is also set for renamings (see sinfo.ads) + -- Body_To_Inline is also set for renamings (see sinfo.ads). For a + -- true inlining, Orig_Bod has code rather than being an entity. elsif Nkind (Orig_Bod) in N_Entity then - if not Has_Pragma_Inline (Subp) then - return; - end if; + return; -- Skip inlining if the function returns an unconstrained type using -- an extended return statement since this part of the new inlining Index: exp_ch6.adb =================================================================== --- exp_ch6.adb (revision 220843) +++ exp_ch6.adb (working copy) @@ -3778,12 +3778,17 @@ or else Nkind (Unit_Declaration_Node (Subp)) /= N_Subprogram_Declaration or else No (Body_To_Inline (Unit_Declaration_Node (Subp))) + or else Nkind (Body_To_Inline (Unit_Declaration_Node (Subp))) in + N_Entity then Add_Inlined_Body (Subp, Call_Node); -- Front end expansion of simple functions returning unconstrained - -- types (see Check_And_Split_Unconstrained_Function) and simple - -- renamings inlined by the front end (see Build_Renamed_Body). + -- types (see Check_And_Split_Unconstrained_Function). Note that the + -- case of a simple renaming (Body_To_Inline in N_Entity above, see + -- also Build_Renamed_Body) cannot be expanded here because this may + -- give rise to order-of-elaboration issues for the types of the + -- parameters of the subprogram, if any. else Expand_Inlined_Call (Call_Node, Subp, Orig_Subp);