From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42c.google.com with SMTP id bn26so16865743wrb.0 for ; Thu, 05 Jan 2023 06:39:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lhO8bXHlAhmCJkz3Uo+Jowej51I9U7mCN7ZHbyjC5sY=; b=JnOm7u2NwFW6uEkWNtH15g40HvhFecWI7br+M4A1O83WJcXsTgaQA8aHyM0fe0iPwI bE8ErwCa+frNBd2WQn5VGVPzj5HrnpjTebTPIRI7PeXQsUFvhz+uXeSL7Gx/FjpzwTGh sXXYlSkXNiSKJlLGiDFVibBVHsFKk6g5B5jnlwNxqMZqsGxQVn8DJ/xt0O5HJg7vm6AH /ny72QqG4NSIW5bBTAIzzOxvUMVyuhFizgMw0Pb4T669D04CgotBZWhc+zE891ujE66N 2knGlJV/YcouC9uDTmrPD1vHTWV9JbNJPfJAzRXMtknh0AzxjtGJSfTZEtwU8GQnbWvI MOaA== 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-Google-Smtp-Source: AMrXdXshpi2ZBpJenDCvRIGMR/jjrnpDhRROABr5cMG4xI6ohF9LV+UyovdvDoeaeKyOtqDxDw13qw== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- -- --