From patchwork Mon Jun 11 09:22:30 2018 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: 927548 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-479436-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FYKXQOS5"; 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 4146xh3Skvz9ryk for ; Mon, 11 Jun 2018 19:23:04 +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=rTHGtzI3mSirEUZEfPMrO/oyFDzb5R6Gtp2uevN+LsnsYP+22v JoEExWfpYo9j230otlcsQZlLkLdeAV9vsrIYfSyM/6GmT9ATcgOXYzZo0ynymJM5 jsKeR3ao9wkcScmaGEuUeu/56+HA+IpGCBrXG0oMyhWFzgyob+RKlLfNw= 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=Timg0awA8AN/NFbCBuKgmmMc8sA=; b=FYKXQOS5m2Kd5Nb7vQRx 0iFPekd65iTKw8VXOW3iSVvLiW5P2/MxNL7gzmnx1A0m9zAsQ1GS0I7EiFpP3aUW 876hA0Uw2LS7x2i/lSMRd7xp3FfzJK3Lu2xvAa1etrpbIOq7woJ9D3lPz2itlEek OSTnON0nxhGV4xh0OG6npWQ= Received: (qmail 23400 invoked by alias); 11 Jun 2018 09:22:34 -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 23253 invoked by uid 89); 11 Jun 2018 09:22:33 -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, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=candidates, bodies, Abandon, abandon 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; Mon, 11 Jun 2018 09:22:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9FE66560ED; Mon, 11 Jun 2018 05:22:30 -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 idAdLk14YzWx; Mon, 11 Jun 2018 05:22:30 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 8E8F8560EC; Mon, 11 Jun 2018 05:22:30 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 8DAB354C; Mon, 11 Jun 2018 05:22:30 -0400 (EDT) Date: Mon, 11 Jun 2018 05:22:30 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Mark extended return of unconstrained type as never inlined Message-ID: <20180611092230.GA134945@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Calls to subprograms whose body was an extended return of an unconstrained type were marked as not inlined, while the subprogram itself was marked as always inlined. This was inconsistent and could lead to crash in GNATprove. Now such subprograms are marked as not candidates for inlining. This mostly impacts GNATprove, as it relates to frontend inlining which is not used anymore in normal compilation. Tested on x86_64-pc-linux-gnu, committed on trunk 2018-06-11 Yannick Moy gcc/ada/ * inline.adb (Build_Body_To_Inline): Consider case of extended return of unconstrained type as one case where inlining is not supported. (Expand_Inlined_Call): Remove special case for body as extended return of unconstrained type. --- gcc/ada/inline.adb +++ gcc/ada/inline.adb @@ -879,6 +879,10 @@ package body Inline is Body_To_Analyze : Node_Id; Max_Size : constant := 10; + function Has_Extended_Return return Boolean; + -- This function returns True if the subprogram has an extended return + -- statement. + function Has_Pending_Instantiation return Boolean; -- If some enclosing body contains instantiations that appear before -- the corresponding generic body, the enclosing body has a freeze node @@ -899,6 +903,49 @@ package body Inline is -- unconstrained type, the secondary stack is involved, and it -- is not worth inlining. + ------------------------- + -- Has_Extended_Return -- + ------------------------- + + function Has_Extended_Return return Boolean is + Body_To_Inline : constant Node_Id := N; + + function Check_Return (N : Node_Id) return Traverse_Result; + -- Returns OK on node N if this is not an extended return statement + + ------------------ + -- Check_Return -- + ------------------ + + function Check_Return (N : Node_Id) return Traverse_Result is + begin + case Nkind (N) is + when N_Extended_Return_Statement => + return Abandon; + + -- Skip locally declared subprogram bodies inside the body to + -- inline, as the return statements inside those do not count. + + when N_Subprogram_Body => + if N = Body_To_Inline then + return OK; + else + return Skip; + end if; + + when others => + return OK; + end case; + end Check_Return; + + function Check_All_Returns is new Traverse_Func (Check_Return); + + -- Start of processing for Has_Extended_Return + + begin + return Check_All_Returns (N) /= OK; + end Has_Extended_Return; + ------------------------------- -- Has_Pending_Instantiation -- ------------------------------- @@ -1048,7 +1095,16 @@ package body Inline is and then not Is_Access_Type (Etype (Spec_Id)) and then not Is_Constrained (Etype (Spec_Id)) then - if not Has_Single_Return (N) then + if not Has_Single_Return (N) + + -- Skip inlining if the function returns an unconstrained type + -- using an extended return statement since this part of the + -- new inlining model which is not yet supported by the current + -- implementation. ??? + + or else (Returns_Unconstrained_Type (Spec_Id) + and then Has_Extended_Return) + then Cannot_Inline ("cannot inline & (unconstrained return type)?", N, Spec_Id); return; @@ -2873,18 +2929,6 @@ package body Inline is elsif Nkind (Orig_Bod) in N_Entity then return; - - -- Skip inlining if the function returns an unconstrained type using - -- an extended return statement since this part of the new inlining - -- model which is not yet supported by the current implementation. ??? - - elsif Is_Unc - and then - Nkind (First (Statements (Handled_Statement_Sequence (Orig_Bod)))) = - N_Extended_Return_Statement - and then not Back_End_Inlining - then - return; end if; if Nkind (Orig_Bod) = N_Defining_Identifier