From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 1715F399C008 for ; Wed, 5 May 2021 08:20:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1715F399C008 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 84643561EB; Wed, 5 May 2021 04:20:05 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 7bFh0RPxjLVR; Wed, 5 May 2021 04:20:05 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 5DABD1174DE; Wed, 5 May 2021 04:20:05 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 5CD99103; Wed, 5 May 2021 04:20:05 -0400 (EDT) Date: Wed, 5 May 2021 04:20:05 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Do not use hash function for enumeration Value with trampolines Message-ID: <20210505082005.GA31323@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 05 May 2021 08:20:15 -0000 --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This prevents the generation of the new perfect hash function for the Value attribute of local enumeration types when the target still uses trampolines to implement pointers to local subprograms. The generation of trampolines would be unexpected in these circumstances and maybe even forbidden by the No_Implicit_Dynamic_Code restriction. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_imgv.adb: Add with/use clauses for Targparm. (Build_Enumeration_Image_Tables): Set type of Threshold to Nat and initialize it to Nat'Last if the type is local and the target does not support descriptors. Adjust Threshold_For_Size similarly. (Expand_Value_Attribute): Minor tweaks. --2fHTh5uZTiUOsy+g Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -43,6 +43,7 @@ with Sinfo; use Sinfo; with Snames; use Snames; with Stand; use Stand; with Stringt; use Stringt; +with Targparm; use Targparm; with Tbuild; use Tbuild; with Ttypes; use Ttypes; with Uintp; use Uintp; @@ -104,11 +105,16 @@ package body Exp_Imgv is -- until the end of the processing and to make sure that it is always -- exactly spent on all possible paths from this point. - Threshold : constant := 3; + Threshold : constant Nat := + (if Is_Library_Level_Entity (E) + or else not Always_Compatible_Rep_On_Target + then 3 + else Nat'Last); -- Threshold above which we want to generate the hash function in the - -- default case. + -- default case. We avoid doing it if this would cause a trampoline to + -- be generated because the type is local and descriptors are not used. - Threshold_For_Size : constant := 9; + Threshold_For_Size : constant Nat := Nat'Max (Threshold, 9); -- But the function and its tables take a bit of space so the threshold -- is raised when compiling for size. @@ -236,8 +242,9 @@ package body Exp_Imgv is Append_Table_To (Act, Eind, Nlit, Ityp, Ind); - -- If the number of literals is at most 3, then we are done. Otherwise - -- we compute a (perfect) hash function for use by the Value attribute. + -- If the number of literals is not greater than Threshold, then we are + -- done. Otherwise we compute a (perfect) hash function for use by the + -- Value attribute. if Nlit > Threshold then -- We start to count serial numbers from here @@ -1483,14 +1490,18 @@ package body Exp_Imgv is Btyp : constant Entity_Id := Base_Type (Typ); Rtyp : constant Entity_Id := Root_Type (Typ); Exprs : constant List_Id := Expressions (N); - Vid : RE_Id; Args : List_Id; Func : RE_Id; Ttyp : Entity_Id; + Vid : RE_Id; begin Args := Exprs; + -- Fall through for all cases except user-defined enumeration type + -- and decimal types, with Vid set to the Id of the entity for the + -- Value routine and Args set to the list of parameters for the call. + if Rtyp = Standard_Character then Vid := RE_Value_Character; @@ -1693,10 +1704,6 @@ package body Exp_Imgv is return; end if; - -- Fall through for all cases except user-defined enumeration type - -- and decimal types, with Vid set to the Id of the entity for the - -- Value routine and Args set to the list of parameters for the call. - -- Compiling package Ada.Tags under No_Run_Time_Mode we disable the -- expansion of the attribute into the function call statement to avoid -- generating spurious errors caused by the use of Integer_Address'Value --2fHTh5uZTiUOsy+g--