From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 7926F3969810 for ; Wed, 7 Jul 2021 16:24:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7926F3969810 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x135.google.com with SMTP id t17so5360737lfq.0 for ; Wed, 07 Jul 2021 09:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=k/9ewla+lGyTqyjrnIRMEJAnGHWsoxuOUEiWqP2rRbs=; b=BawVz4rO6qb2lP3hn6AxZQ3ng1X7lLaUTtegp1ZjBHlCLaGU0BuOLklvFfvqYK+4r7 q5HrMJw/rboslM7XAStRrAT3OTRUDBFVyPW+KQeOLKYBBLzKyxvF70bOL/pW2IwHOORU RXN1Pnlk/Ejg7YCnp2lVPTt5DeHSuln8NibeWZryHPI0uoluwEcPREO29aTzRV5VNedU k6GgIiswzk9rlwVbPDoTJOSlzUxaDHO2e4IxaFidXYZTF53py6zkjCQbGqbSx4Q3a1x3 4ZmFPrSdShg/KBza9KgMmX8jVFXI82tpUfmL9v/3qKrjcDgGEF91NXrUaVBrzf1VvMdP uPlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=k/9ewla+lGyTqyjrnIRMEJAnGHWsoxuOUEiWqP2rRbs=; b=BTUL8kN5nbeR5qc5xTJM3EkNL7ZLjlBm1RZ/aZodKEhNf1gMYRdcWHOsp4NVYPalrf SkHpqJ3SNbvbFS5iCZsR7S2tPWBDMjqzTbNXVvdNG6BLc2KrQSvs3ntoRcDznjT6kxmq Wf+XRebDJ6Wj650V/tfGfXe7WQ9YdTLHHSEZMBieHODyJIHtGAWNWBFGN0HeECLm6b5y 72bZQNrxZfPUDac4+zapg+AhcILm5qS06CX0GJ+LXi0QWaJeoKTxQbXqhVv3kTRDLqJB sfQgmAWLXN4Y2as6Xn+f1aEBHxA+BdlRp4zp+yB+yYrQxEcYeyROrbZ5axRa3hwqoG3x WjWA== X-Gm-Message-State: AOAM533d3STPc4qYcNRGnqx8Bs+ntKYEaiF6Y04wSyOb3foJ7OEthvDM J8mrhVSya3i/sHj9obuLraJKjLPgKkxLAg== X-Google-Smtp-Source: ABdhPJzto3l0Mr8IVnYavbchkXLPg25WPnnstKC6x9whRl/jeaN4BWFuNLsuT9GkIin8HUX00d+EZw== X-Received: by 2002:a2e:84c8:: with SMTP id q8mr20602066ljh.124.1625675090315; Wed, 07 Jul 2021 09:24:50 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id g15sm1508583lfv.72.2021.07.07.09.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 09:24:49 -0700 (PDT) Date: Wed, 7 Jul 2021 16:24:47 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Simplify handling of Generate_Code flag for compilation units Message-ID: <20210707162447.GA2542841@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 07 Jul 2021 16:24:53 -0000 --/04w6evG8XlLl3ft Content-Type: text/plain; charset=us-ascii Content-Disposition: inline There are three kinds of units that require code generation: the main unit, its corresponding spec and generic instances needed by the main unit. Previously the main unit and its corresponding spec were flagged as requiring code generation just before calling the backend, while instance units were flagged while they were created, which was inconsistent. Now all of them are flagged as soon as they are created, which both appears to be simpler and makes the Generate_Code flag valid all the time. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gnat1drv.adb (Gnat1drv): Remove flagging of main unit and its corresponding spec as requiring code generation; now the flags are set much earlier. * lib-load.adb (Load_Main_Source): Set Generate_Code flag on the main unit source. (Make_Instance_Unit): Copy Generate_Code flag from the main unit to instance units. * lib-writ.adb (Write_ALI): Remove redundant condition; Generate_Code flag is always set for the main unit. * par-load.adb (Load): Set Generate_Code flag on the main unit's corresponding spec, if any. --/04w6evG8XlLl3ft Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb --- a/gcc/ada/gnat1drv.adb +++ b/gcc/ada/gnat1drv.adb @@ -1287,29 +1287,6 @@ begin Exit_Program (E_Errors); end if; - -- Set Generate_Code on main unit and its spec. We do this even if are - -- not generating code, since Lib-Writ uses this to determine which - -- units get written in the ali file. - - Set_Generate_Code (Main_Unit); - - -- If we have a corresponding spec, and it comes from source or it is - -- not a generated spec for a child subprogram body, then we need object - -- code for the spec unit as well. - - if Nkind (Unit (Main_Unit_Node)) in N_Unit_Body - and then not Acts_As_Spec (Main_Unit_Node) - then - if Nkind (Unit (Main_Unit_Node)) = N_Subprogram_Body - and then not Comes_From_Source (Library_Unit (Main_Unit_Node)) - then - null; - else - Set_Generate_Code - (Get_Cunit_Unit_Number (Library_Unit (Main_Unit_Node))); - end if; - end if; - -- Case of no code required to be generated, exit indicating no error if Original_Operating_Mode = Check_Syntax then diff --git a/gcc/ada/lib-load.adb b/gcc/ada/lib-load.adb --- a/gcc/ada/lib-load.adb +++ b/gcc/ada/lib-load.adb @@ -364,7 +364,7 @@ package body Lib.Load is Error_Location => No_Location, Expected_Unit => No_Unit_Name, Fatal_Error => None, - Generate_Code => False, + Generate_Code => True, Has_RACW => False, Filler => False, Ident_String => Empty, @@ -964,13 +964,12 @@ package body Lib.Load is Units.Increment_Last; if In_Main then - Units.Table (Units.Last) := Units.Table (Main_Unit); - Units.Table (Units.Last).Cunit := Library_Unit (N); - Units.Table (Units.Last).Generate_Code := True; + Units.Table (Units.Last) := Units.Table (Main_Unit); + Units.Table (Units.Last).Cunit := Library_Unit (N); Init_Unit_Name (Units.Last, Unit_Name (Main_Unit)); - Units.Table (Main_Unit).Cunit := N; - Units.Table (Main_Unit).Version := Source_Checksum (Sind); + Units.Table (Main_Unit).Cunit := N; + Units.Table (Main_Unit).Version := Source_Checksum (Sind); Init_Unit_Name (Main_Unit, Get_Body_Name (Unit_Name (Get_Cunit_Unit_Number (Library_Unit (N))))); diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb --- a/gcc/ada/lib-writ.adb +++ b/gcc/ada/lib-writ.adb @@ -1253,7 +1253,7 @@ package body Lib.Writ is -- for which we have generated code for Unit in Units.First .. Last_Unit loop - if Units.Table (Unit).Generate_Code or else Unit = Main_Unit then + if Units.Table (Unit).Generate_Code then if not Has_No_Elaboration_Code (Cunit (Unit)) then Main_Restrictions.Violated (No_Elaboration_Code) := True; exit; diff --git a/gcc/ada/par-load.adb b/gcc/ada/par-load.adb --- a/gcc/ada/par-load.adb +++ b/gcc/ada/par-load.adb @@ -265,6 +265,12 @@ begin -- and this is also where we generate the SCO's for this spec. if Cur_Unum = Main_Unit then + + -- We generate code for the main unit body, so we need to generate + -- code for its spec too. + + Set_Generate_Code (Unum, True); + Main_Unit_Entity := Cunit_Entity (Unum); if Generate_SCO then --/04w6evG8XlLl3ft--