From patchwork Thu Jan 5 14:39:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 39620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp334395wrt; Thu, 5 Jan 2023 06:46:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRVAAydEilaj7Tn2uO1h2QM5V09fAXddOwC2bKn5IXUyzljg3qNJb5WNzSnppec5hCiCYr X-Received: by 2002:a17:906:5dd2:b0:7d5:29e1:15ea with SMTP id p18-20020a1709065dd200b007d529e115eamr45427374ejv.8.1672929960341; Thu, 05 Jan 2023 06:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672929960; cv=none; d=google.com; s=arc-20160816; b=cYsv1fyyWmJ8vkGk7QX3LnonE/ysvOlQZZ9Rfbdpauh4tuAvCvCojGcKUp9DeZR1V3 VE/oAK+JHOtfPeMa9hoxkABQgfXP27xBydTucizipBIAEXBnD8zx8ewylMo2MIQzsarA mqF/+BnvBsk3GddUqgxXYAEf1daRRDZH4KpaqmIywnXBMXxaisSdOM1o7Got1OwlId6q PqedmuIVTqZSJY/zmgeDCHLUIAno1+b7LIStx2Q6iUT725NJ4g5Fh3g1CcCxU3jbdfci p3A39ij5GX89LgEwmdESVv5GYNCu2jAGi0amPrnZ6SAVGMvageRhaPr+RqdiRVGYetx7 fbhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=lhO8bXHlAhmCJkz3Uo+Jowej51I9U7mCN7ZHbyjC5sY=; b=bWxXJRhyBOU38cA9OWokkTRZr4FZ+8TvWCZ7dtTsGDlG25OAH3+gnhTBwB53ZbKK4t SGn31bETCSUy4x6d0e6RFCiu4SoQqakh3QVMT234WISb/lBYCqTWFMNtbr4/5twfBFrw wcHZlCo74wGcTD/4ct2k5XXRiq8OStXvAUuTWOvexw/LnSLQrR8UvcmOrKDcm4Jz6s3S eR4ie+J1Sey56j9IYOMVPl8Y2ZYxTxR3uNUa3pGucWjfW3Fv7aexDrod47VQPZ8wy9Hz wgw5ZIs2Jger/a/ry9ihCj4rYvmVUGhbOJW5q3/bod4GFSNnEegjBqUu4fqjBMHhVrqB oPbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eAyrM9hc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gs35-20020a1709072d2300b0078e15c30a6csi36226009ejc.559.2023.01.05.06.46.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 06:46:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eAyrM9hc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0823D3887F5F for ; Thu, 5 Jan 2023 14:42:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0823D3887F5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672929745; bh=lhO8bXHlAhmCJkz3Uo+Jowej51I9U7mCN7ZHbyjC5sY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=eAyrM9hcaS31UMHv2Wu0bFk6at5iqPOKuwvQCOA3/zb/6V6nmieyqVkKDquZqiqST 3N9pLa0WvTkCS1hg6mWLfrRE3a0yztF2owtell06U2BffQdH/k+s3KkLP6tJSJrpPz yPTsZp3BcWbW+5hxZB6wix8MNSqLpjgmGk4n52LA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id D00903857C48 for ; Thu, 5 Jan 2023 14:39:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D00903857C48 Received: by mail-wr1-x42c.google.com with SMTP id bn26so16865743wrb.0 for ; Thu, 05 Jan 2023 06:39:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lhO8bXHlAhmCJkz3Uo+Jowej51I9U7mCN7ZHbyjC5sY=; b=w5OxoRcnRkdrBs0yRyyIi+Tdk3vf3vK0N7HwgG+wWtiVC3meVVJj2gsTGVr47EPZQu Rk16ZBj3XRlJsrLLuZKymIdPDBvtZYb3AmT+tL1q6eXFoe2hq1tZXd8fc5CstLUzFJ4o EYVGa1aA7guFmzBOSOC/G02UX7wAI4MjeZv2lG/FtYWFnqKdfyIyQMmjjJBl5leUVYwV 6nIZdI/bnU5pmElbYMYlbuN0cKQUp8xQSt4vuNOiAehOXBCK/M4GF5eJf604HKC6YIOk zcnyc2T03end39i7wDnRnGVDovsFGkXXm/DlftBQLyQh8fkhv700PKCL0l/DIOaYa9ep zfNg== X-Gm-Message-State: AFqh2kr+BKWp5bB7C0IyGDHhzmorDK+A3uWffqwcyPeSholFlqU2/y79 Wh68uf1s081ilzw5PvmyOKCOU2vrxMlCPIaHufM= X-Received: by 2002:a05:6000:18ca:b0:244:48b3:d138 with SMTP id w10-20020a05600018ca00b0024448b3d138mr29620472wrq.54.1672929575678; Thu, 05 Jan 2023 06:39:35 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id t18-20020a5d42d2000000b00288a3fd9248sm22627835wrr.91.2023.01.05.06.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 06:39:35 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Simplify new expansion of contracts Date: Thu, 5 Jan 2023 15:39:33 +0100 Message-Id: <20230105143933.155824-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754194205838237982?= X-GMAIL-MSGID: =?utf-8?q?1754194205838237982?= From: Eric Botcazou We can now use an extended return statement in all cases since it no longer generates an extra copy for nonlimited by-reference types. gcc/ada/ * contracts.adb (Build_Subprogram_Contract_Wrapper): Generate an extended return statement in all cases. (Expand_Subprogram_Contract): Adjust comment. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 105 ++---------------------------------------- 1 file changed, 5 insertions(+), 100 deletions(-) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 59121ca9ea2..77c231e1d4f 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -30,7 +30,6 @@ with Einfo.Entities; use Einfo.Entities; with Einfo.Utils; use Einfo.Utils; with Elists; use Elists; with Errout; use Errout; -with Exp_Ch6; use Exp_Ch6; with Exp_Prag; use Exp_Prag; with Exp_Tss; use Exp_Tss; with Exp_Util; use Exp_Util; @@ -1616,40 +1615,8 @@ package body Contracts is -- preserving the result for the purpose of evaluating postconditions, -- contracts, type invariants, etc. - -- In the case of a regular function, generate: + -- In the case of a function, generate: -- - -- function Original_Func (X : in out Integer) return Typ is - -- - -- - -- - -- function _Wrapped_Statements return Typ is - -- - -- begin - -- - -- end; - -- - -- begin - -- declare - -- type Axx is access all Typ; - -- Rxx : constant Axx := _Wrapped_Statements'reference; - -- Result_Obj : Typ renames Rxx.all; - -- - -- begin - -- - -- return Rxx.all; - -- end; - -- end; - -- - -- This sequence is recognized by Expand_Simple_Function_Return as a - -- tail call, in other words equivalent to "return _Wrapped_Statements;" - -- and thus the copy to the anonymous return object is elided, including - -- a pair of calls to Adjust/Finalize for types requiring finalization. - - -- Note that an extended return statement does not yield the same result - -- because the copy of the return object is not elided by GNAT for now. - - -- Or else, in the case of a BIP function, generate: - -- function Original_Func (X : in out Integer) return Typ is -- -- @@ -1733,9 +1700,9 @@ package body Contracts is (Handled_Statement_Sequence (Body_Decl), Stmts); -- Generate the post-execution statements and the extended return - -- when the subprogram being wrapped is a BIP function. + -- when the subprogram being wrapped is a function. - elsif Is_Build_In_Place_Result_Type (Ret_Type) then + else Set_Statements (Handled_Statement_Sequence (Body_Decl), New_List ( Make_Extended_Return_Statement (Loc, Return_Object_Declarations => New_List ( @@ -1751,65 +1718,6 @@ package body Contracts is Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)))); - - -- Declare a renaming of the result of the call to the wrapper and - -- append a return of the result of the call when the subprogram is - -- a function, after manually removing the side effects. Note that - -- we cannot call Remove_Side_Effects here because nothing has been - -- analyzed yet and we cannot return the renaming itself because - -- Expand_Simple_Function_Return expects an explicit dereference. - - else - declare - A_Id : constant Node_Id := Make_Temporary (Loc, 'A'); - R_Id : constant Node_Id := Make_Temporary (Loc, 'R'); - - begin - Set_Statements (Handled_Statement_Sequence (Body_Decl), New_List ( - Make_Block_Statement (Loc, - - Declarations => New_List ( - Make_Full_Type_Declaration (Loc, - Defining_Identifier => A_Id, - Type_Definition => - Make_Access_To_Object_Definition (Loc, - All_Present => True, - Null_Exclusion_Present => True, - Subtype_Indication => - New_Occurrence_Of (Ret_Type, Loc))), - - Make_Object_Declaration (Loc, - Defining_Identifier => R_Id, - Object_Definition => New_Occurrence_Of (A_Id, Loc), - Constant_Present => True, - Expression => - Make_Reference (Loc, - Make_Function_Call (Loc, - Name => New_Occurrence_Of (Wrapper_Id, Loc)))), - - Make_Object_Renaming_Declaration (Loc, - Defining_Identifier => Result, - Subtype_Mark => New_Occurrence_Of (Ret_Type, Loc), - Name => - Make_Explicit_Dereference (Loc, - New_Occurrence_Of (R_Id, Loc)))), - - Handled_Statement_Sequence => - Make_Handled_Sequence_Of_Statements (Loc, - Statements => Stmts)))); - - Append_To (Stmts, - Make_Simple_Return_Statement (Loc, - Expression => - Make_Explicit_Dereference (Loc, - New_Occurrence_Of (R_Id, Loc)))); - - -- It is required for Is_Related_To_Func_Return to return True - -- that the temporary Rxx be related to the expression of the - -- simple return statement built just above. - - Set_Related_Expression (R_Id, Expression (Last (Stmts))); - end; end if; end Build_Subprogram_Contract_Wrapper; @@ -3479,9 +3387,7 @@ package body Contracts is -- end _Wrapped_Statements; -- begin - -- declare - -- Result : ... renames _Wrapped_Statements; - -- begin + -- return Result : constant ... := _Wrapped_Statements do -- -- -- @@ -3489,8 +3395,7 @@ package body Contracts is -- -- --