From patchwork Mon May 29 08:29:46 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: 70235 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CD6D393BC1F for ; Mon, 29 May 2023 08:38:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CD6D393BC1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685349519; bh=t6Id9VU4Pqz2Q0s4POPEKs2e9mTDpTVsgbvF3k3kzYY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yuCd05gDZI/TkJdyjcJA9P3VkGBecaB7roFWrRRBylFyamawpI4dC9Vrz3Mjqqar4 v60hs/QVuF0+d9qu+J1nwc/pm8VoJjA7HlQIGjsD9uxt+T8Djm2MFt/0tAqyYE8vQ7 dKnz8polyqlAAWRXCoGmZG7RmiVvMF9QxNL03nXc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 02779384603C for ; Mon, 29 May 2023 08:29:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02779384603C Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f6e13940daso31854685e9.0 for ; Mon, 29 May 2023 01:29:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685348987; x=1687940987; 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=t6Id9VU4Pqz2Q0s4POPEKs2e9mTDpTVsgbvF3k3kzYY=; b=SzU5skSy0jllOoO0SS1+uRb/7URKW0RDsXhO91VdSPwFmm48mhSo7CkCIZnQLHip4r JpGJK5k/x51bzRGTw9Tv5iZNfQT205zqDP4IIGVVoFJXI3mqAkiX0wWVnBBbixPHxZ2y +Uqul1pmsXXARNCyUCr89a2Pr5Xl8QOu8t2WGJGKf1M0f6EKCzoOpfK74MBOHc2u9ZnP NyTgIG9p5mfXVqb7nH34Bks1DTBzvYH003iIRG9BOxYTVCATLpEXi7LqYXO586xcLymh L1G20UI/OUr8X8EhpN1KPrW4QCw7haZY+P2VumJfUFIHLOFJDnvx5wIV+Ku55mZvSWg6 SAgA== X-Gm-Message-State: AC+VfDzenc7bkf30F7pr7/WI4uKGo2HJJQEgYV1DQ2l9XRktAQhONDB/ 3Mc9kifQ9WcV3KTRzFeqcwJF+lzCBpF98G2r8NBCsA== X-Google-Smtp-Source: ACHHUZ6eALRP4GSkq0dwCLfANHFuy/eVa17WnUP8BRqvv9HvjUZzpAmjELOmo4klAJqbpCN7BOWtNQ== X-Received: by 2002:a1c:6a03:0:b0:3f5:6e5:1689 with SMTP id f3-20020a1c6a03000000b003f506e51689mr9386524wmc.17.1685348987630; Mon, 29 May 2023 01:29:47 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id u15-20020a05600c210f00b003f42d8dd7d1sm17159248wml.7.2023.05.29.01.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:29:47 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Attach pre/post on access-to-subprogram to internal subprogram type Date: Mon, 29 May 2023 10:29:46 +0200 Message-Id: <20230529082946.2410945-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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, T_SCC_BODY_TEXT_LINE 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Piotr Trojanek Aspects Pre/Post that annotate access-to-subprogram type were attached to the source entity (whose kind is either E_Access_Subprogram_Type or E_Access_Protected_Subprogram_Type). However, it is more convenient to attach them to the internal entity (whose kind is E_Subprogram_Type), so that both Pre/Post aspects and First_Formal/Next_Formal chain are attached to the same entity, just like for ordinary subprograms. The drawback of having the Post aspect attached to an internal entity is that name in prefixes of attribute Result no longer match the name of entity where this Post aspect is attached. However, currently there is no code that relies on this matching and, in general, there are fewer routines that deal with attribute Result so they are easier to adapt than the code that queries the Pre/Post aspects. gcc/ada/ * contracts.adb (Add_Pre_Post_Condition): Attach pre/post aspects to E_Subprogram_Type entity. (Analyze_Entry_Or_Subprogram_Contract): Adapt to use full type declaration for a contract attached to E_Subprogram_Type entity. * sem_prag.adb (Analyze_Pre_Post_Condition): Add pre/post aspects to the designed type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 12 ++++++++---- gcc/ada/sem_prag.adb | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 15b65ee4c06..7625abf9554 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -334,7 +334,7 @@ package body Contracts is if Is_OK_Classification then Add_Classification; - elsif Ekind (Id) in Access_Subprogram_Kind + elsif Ekind (Id) = E_Subprogram_Type and then Prag_Nam in Name_Precondition | Name_Postcondition then @@ -665,7 +665,10 @@ package body Contracts is Freeze_Id : Entity_Id := Empty) is Items : constant Node_Id := Contract (Subp_Id); - Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id); + Subp_Decl : constant Node_Id := + (if Ekind (Subp_Id) = E_Subprogram_Type + then Associated_Node_For_Itype (Subp_Id) + else Unit_Declaration_Node (Subp_Id)); Saved_SM : constant SPARK_Mode_Type := SPARK_Mode; Saved_SMP : constant Node_Id := SPARK_Mode_Pragma; @@ -1593,8 +1596,9 @@ package body Contracts is -- Analyze Pre/Post on access-to-subprogram type - if Is_Access_Subprogram_Type (Type_Id) then - Analyze_Entry_Or_Subprogram_Contract (Type_Id); + if Ekind (Type_Id) in Access_Subprogram_Kind then + Analyze_Entry_Or_Subprogram_Contract + (Directly_Designated_Type (Type_Id)); end if; end Analyze_Type_Contract; diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 0d62b04cc37..0de410a2392 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -5265,7 +5265,11 @@ package body Sem_Prag is -- Chain the pragma on the contract for further processing by -- Analyze_Pre_Post_Condition_In_Decl_Part. - Add_Contract_Item (N, Subp_Id); + if Ekind (Subp_Id) in Access_Subprogram_Kind then + Add_Contract_Item (N, Directly_Designated_Type (Subp_Id)); + else + Add_Contract_Item (N, Subp_Id); + end if; -- Fully analyze the pragma when it appears inside an entry or -- subprogram body because it cannot benefit from forward references.