From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 350193955C8D for ; Thu, 2 Jun 2022 09:09:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 350193955C8D Received: by mail-ej1-x636.google.com with SMTP id n10so8721612ejk.5 for ; Thu, 02 Jun 2022 02:09:15 -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=hhe2d5Gb2JcFcCaC3nI00vWnNUIb4G6oDwcBBrdgDL4=; b=yz7q7g/I0uGfyD70OF1j0lCvCAEeyhP4CjMvrR2NNqtcWAHoUVdJ0Pvby3/jN5tHHD 5idbGy8DSGhNyT3zOFgC+8Lv1LnVKZsikcwtOxlRlB3Az9PNQfXY+iSXrNLpkzOMZI5F 8lzX4EB4bVyFfOs68i34YxK5rlbnrblM35HD5m54+mOWFekJ71R+fvPmnmfEyZUdt01c 5MiNxXvIHCjODgWD8vIETHu8GoC3nLjcJWw4e6qAHLw6lqHvc7iRFFL0osFAm0597HgS MVTj7lZpw4rp6kMy5qJeu2/FGq8k5w6rzZzRX+ObIBBQj/NKwitx41ygrCLp77Ds0JO2 m8qA== X-Gm-Message-State: AOAM533ksufaDe6wE/1ISawRx/+TBeIxF68PipzKhkuO1oLkDba7vztt b6S/91xKYqy4bMvotg9riV0SANRs82HPbA== X-Google-Smtp-Source: ABdhPJywQ1ORds4HTNz1W6BTjijzRFLv0MHv9oJZZqvClhFoQLgx+wV0VsQtLAVQbE306+hFx3WXFw== X-Received: by 2002:a17:907:d25:b0:707:f440:eddb with SMTP id gn37-20020a1709070d2500b00707f440eddbmr3311005ejc.216.1654160954796; Thu, 02 Jun 2022 02:09:14 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id p4-20020a170906784400b00702d8b43df3sm1529356ejm.167.2022.06.02.02.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 02:09:14 -0700 (PDT) Date: Thu, 2 Jun 2022 09:09:13 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Restore full generation of static dispatch tables with -gnatzr Message-ID: <20220602090913.GA1010989@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Qxx1br4bt0+wmkIi" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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-List-Received-Date: Thu, 02 Jun 2022 09:09:16 -0000 --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The -gnatzr switch triggers the creation of distribution stubs for use by the implementation of PolyORB. Now these stubs declare tagged types and are generated at the very end of the analysis of compilation units, after the static dispatch tables have been built, so these tables are missing for the tagged types of the stubs. Therefore this change defers the generation of static dispatch tables for compilation units, which is the common case, until after the stubs are (potentially) generated. For the other cases, in particular the generic instances that are not compilation units, nothing is changed. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch7.adb (Expand_N_Package_Body): Build static dispatch tables only for units that are not compilation units, unless they are generic instances. Do not push a scope for this. (Expand_N_Package_Declaration): Build static dispatch tables only for units that are both not compilation units and generic instances. * exp_disp.adb (Build_Static_Dispatch_Tables): Remove redundant early return. Push a scope for package bodies. * sem_ch10.adb: Add with and use clauses for Exp_Disp. (Analyze_Compilation_Unit): Build static dispatch tables here. --Qxx1br4bt0+wmkIi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -5876,16 +5876,20 @@ package body Exp_Ch7 is -- This is done only for non-generic packages if Ekind (Spec_Id) = E_Package then - Push_Scope (Spec_Id); - - -- Build dispatch tables of library level tagged types + -- Build dispatch tables of library-level tagged types for bodies + -- that are not compilation units (see Analyze_Compilation_Unit), + -- except for instances because they have no N_Compilation_Unit. if Tagged_Type_Expansion and then Is_Library_Level_Entity (Spec_Id) + and then (not Is_Compilation_Unit (Spec_Id) + or else Is_Generic_Instance (Spec_Id)) then Build_Static_Dispatch_Tables (N); end if; + Push_Scope (Spec_Id); + Expand_CUDA_Package (N); Build_Task_Activation_Call (N); @@ -6035,12 +6039,13 @@ package body Exp_Ch7 is Pop_Scope; end if; - -- Build dispatch tables of library-level tagged types + -- Build dispatch tables of library-level tagged types for instances + -- that are not compilation units (see Analyze_Compilation_Unit). if Tagged_Type_Expansion - and then (Is_Compilation_Unit (Id) - or else (Is_Generic_Instance (Id) - and then Is_Library_Level_Entity (Id))) + and then Is_Library_Level_Entity (Id) + and then Is_Generic_Instance (Id) + and then not Is_Compilation_Unit (Id) then Build_Static_Dispatch_Tables (N); end if; diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -524,12 +524,6 @@ package body Exp_Disp is -- Start of processing for Build_Static_Dispatch_Tables begin - if not Expander_Active - or else not Tagged_Type_Expansion - then - return; - end if; - if Nkind (N) = N_Package_Declaration then declare Spec : constant Node_Id := Specification (N); @@ -553,8 +547,15 @@ package body Exp_Disp is end; else pragma Assert (Nkind (N) = N_Package_Body); - Target_List := Declarations (N); - Build_Dispatch_Tables (Target_List); + declare + Spec_Id : constant Entity_Id := Corresponding_Spec (N); + + begin + Push_Scope (Spec_Id); + Target_List := Declarations (N); + Build_Dispatch_Tables (Target_List); + Pop_Scope; + end; end if; end Build_Static_Dispatch_Tables; diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -31,6 +31,7 @@ with Einfo; use Einfo; with Einfo.Entities; use Einfo.Entities; with Einfo.Utils; use Einfo.Utils; with Errout; use Errout; +with Exp_Disp; use Exp_Disp; with Exp_Put_Image; with Exp_Util; use Exp_Util; with Elists; use Elists; @@ -1000,6 +1001,22 @@ package body Sem_Ch10 is end if; end if; + -- Build dispatch tables of library-level tagged types only now because + -- the generation of distribution stubs above may create some of them. + + if Expander_Active and then Tagged_Type_Expansion then + case Nkind (Unit_Node) is + when N_Package_Declaration | N_Package_Body => + Build_Static_Dispatch_Tables (Unit_Node); + + when N_Package_Instantiation => + Build_Static_Dispatch_Tables (Instance_Spec (Unit_Node)); + + when others => + null; + end case; + end if; + -- Remove unit from visibility, so that environment is clean for the -- next compilation, which is either the main unit or some other unit -- in the context. --Qxx1br4bt0+wmkIi--