From patchwork Tue May 17 08:27:31 2022 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: 1632113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=cYGNk+93; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L2Tsg2fddz9s0r for ; Tue, 17 May 2022 18:33:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE8043857428 for ; Tue, 17 May 2022 08:33:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE8043857428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652776404; bh=hcIH/nnme7cJHQnsrMuSzgroSpNdCJ3PxqIAAS+HbrA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=cYGNk+93k4wcrvCJxG6Is8QZ3DcdwSF3zF3a9mxjLINTx0nVc6bU5Fu+LrL2J8KSw 9T9un9rKfticJ2YKBTPtFVhh+se2sVHbmcIzn4U8QxbG8JUMdz/TX6klO/v5mI3mdb vW3NqhtzTWWP3Dv2/kVA/E1tnjNQGmJ3KKLN7SGs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id EF0EC3857404 for ; Tue, 17 May 2022 08:27:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF0EC3857404 Received: by mail-wm1-x335.google.com with SMTP id o12-20020a1c4d0c000000b00393fbe2973dso929006wmh.2 for ; Tue, 17 May 2022 01:27:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=hcIH/nnme7cJHQnsrMuSzgroSpNdCJ3PxqIAAS+HbrA=; b=41h5ZdaiPhkbw9fWMJiizr1385vZ7KKFjj0HRFjXVGUF9jjwgeSwRNSQhtvCyS0ha4 6XGcgIqQU7RI3hS+1+P3t1RvwzBH91PgPs0aeeMW9VPS2tEmkjugRQN+Djk+TSAQMIZt O2Ag7vsS/2Kzwib8g9iwYopYQekdAGAVS/1p68V8Mk2BHZvFa9+sSxvut4y77bG1Sl6M Bv5FqcRzMKtZCfhgK2CNRDQxzSlj4AE0aOnj5etR36JuNnvtqNgjVRoeMTgMZRkaBgIP XVkudJpRdWgN39xKMyfxHi9juh1DU2Qkq3+h7lR5ED/K0TmXQhMv9phLwA5y82k4dfML v92g== X-Gm-Message-State: AOAM531EcQt/b1PJEsIGo40NprG9kDPVOyRBLas1dNlOJ+G3HfVmuVC8 LVBQXuLBaOlShiJmM8/PJCXUF4/igFZjYpsr X-Google-Smtp-Source: ABdhPJz9eXKtZs+l6rJtFxiYsyRkYa+0yZNY2RSyCKfv0ZFYXvCTfXe9hl7N7iYlz8vzequDBaqfFQ== X-Received: by 2002:a7b:c081:0:b0:394:789b:915 with SMTP id r1-20020a7bc081000000b00394789b0915mr20036778wmh.105.1652776052674; Tue, 17 May 2022 01:27:32 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id j15-20020adfb30f000000b0020d042efd11sm6912689wrd.61.2022.05.17.01.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:32 -0700 (PDT) Date: Tue, 17 May 2022 08:27:31 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Use Actions field of freeze nodes for subprograms Message-ID: <20220517082731.GA1087940@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This has a couple of advantages: 1) the actions are analyzed with checks disabled and 2) they are considered elaboration code by Sem_Elab. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch13.adb (Expand_N_Freeze_Entity): Delete freeze nodes for subprograms only if they have no actions. * exp_ch6.adb (Freeze_Subprogram): Put the actions into the Actions field of the freeze node instead of inserting them after it. * sem_elab.adb (Is_SPARK_Semantic_Target): Fix typo in comment. * gcc-interface/trans.cc (process_freeze_entity): Return early for freeze nodes of subprograms with Interface_Alias set. diff --git a/gcc/ada/exp_ch13.adb b/gcc/ada/exp_ch13.adb --- a/gcc/ada/exp_ch13.adb +++ b/gcc/ada/exp_ch13.adb @@ -617,14 +617,12 @@ package body Exp_Ch13 is elsif Is_Subprogram (E) then Exp_Ch6.Freeze_Subprogram (N); - -- Ada 2005 (AI-251): Remove the freezing node associated with the - -- entities internally used by the frontend to register primitives - -- covering abstract interfaces. The call to Freeze_Subprogram has - -- already expanded the code that fills the corresponding entry in - -- its secondary dispatch table and therefore the code generator - -- has nothing else to do with this freezing node. - - Delete := Present (Interface_Alias (E)); + -- Ada 2005 (AI-251): Remove the freeze nodes associated with the + -- entities internally used by the front end to register primitives + -- covering abstract interfaces if they have no side effects. For the + -- others, gigi must discard them after evaluating the side effects. + + Delete := Present (Interface_Alias (E)) and then No (Actions (N)); end if; -- Analyze actions generated by freezing. The init_proc contains source diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -7856,6 +7856,8 @@ package body Exp_Ch6 is declare Typ : constant Entity_Id := Scope (DTC_Entity (Subp)); + L : List_Id; + begin -- Handle private overridden primitives @@ -7895,8 +7897,17 @@ package body Exp_Ch6 is Register_Predefined_DT_Entry (Subp); end if; - Insert_Actions_After (N, - Register_Primitive (Loc, Prim => Subp)); + L := Register_Primitive (Loc, Prim => Subp); + + if Is_Empty_List (L) then + null; + + elsif No (Actions (N)) then + Set_Actions (N, L); + + else + Append_List (L, Actions (N)); + end if; end if; end if; end; diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -9045,6 +9045,11 @@ process_freeze_entity (Node_Id gnat_node) if (kind == E_Class_Wide_Type) return; + /* Likewise for the entities internally used by the front-end to register + primitives covering abstract interfaces, see Expand_N_Freeze_Entity. */ + if (Is_Subprogram (gnat_entity) && Present (Interface_Alias (gnat_entity))) + return; + /* Check for an old definition if this isn't an object with address clause, since the saved GCC tree is the address expression in that case. */ gnu_old diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb --- a/gcc/ada/sem_elab.adb +++ b/gcc/ada/sem_elab.adb @@ -1845,7 +1845,7 @@ package body Sem_Elab is function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean; pragma Inline (Is_SPARK_Semantic_Target); - -- Determine whether arbitrary entity Id nodes a source or internally + -- Determine whether arbitrary entity Id denotes a source or internally -- generated subprogram which emulates SPARK semantics. function Is_Subprogram_Inst (Id : Entity_Id) return Boolean;