From patchwork Mon Jul 3 13:27:12 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: 115360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp523593vqx; Mon, 3 Jul 2023 06:28:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+J3xTm5Ds/UHxsSSOeooU9LHDEz1tVOscJ5RPCRgQ0B3RVPo+PtwbjXcRcKS9llaNFALl X-Received: by 2002:a17:906:7e0d:b0:978:992e:efd1 with SMTP id e13-20020a1709067e0d00b00978992eefd1mr6404649ejr.35.1688390890916; Mon, 03 Jul 2023 06:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390890; cv=none; d=google.com; s=arc-20160816; b=NoPwOg4HZXCLf3dAEfR3Bzmni0t8u/JMWY+dRau6biplVbtQ5IfZ4YPujOgYZ8BTSV DglA9KJuPt4uKtIh5rTxQB/V/a2ZcCIi2n+xbTBz3KOtlvqUynjY2nugDNMJ9czZf/cf zNycujSXZzrsxk74SONuqGGV9aXtZD2PTLeyzP1FwtmE16RW051dByVFPSa+2K7x9XE6 /+M10n/o/0iAOfTDyI2+j3T428x+o9WwpHtKoZrpuvxRPy/BVReXW/Qkbk3qUDDQwNLo qXec6GZj++pkRTXWFcmkWJ13u1BQSUFa3GmIQYsQ/GGyRL6LWtcecVTFj9OsA3jwkvpU DoMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xbEj5XSHLcNxR8Ea9Dhk6Abpk1RWxhSfq4D6WHBVmGY=; fh=hOhsC1930eHatDPYd2EALQ9Ry/g++vvN4vxlQkRuX+0=; b=H+bo9wAi6RJF5IL67Nd7N68DF9C74UkQde6TCcqr1JEop84ZXmx3sFTSIIFSOe87RJ pWMRb3sllSN2gHoqWiHoPI2OnynvpOemQOPGZbchbkvStko0P10LUoMVZiEeqi+F1WJk 3D7jFpxG392BgXmkJ0FaoYkChQSIIPNTscXbhgNGfwlvp9iKYeLNgEh2s+gjzIr02ZBj k4GKO7JSUKGcVnSVCoph54zs/fMIT1iwWfcS5rs+w75q4ZsxKEFG4u87Zw9DC0LNzoEH 3/DT0blKEnAnSe4U44k6P/y1QCsoGR2A99legps0SHtOLk0mwEMrmH3B4/20niFyf6OQ o1Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bKKDW0oQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gl8-20020a170906e0c800b00992b63c9f9csi5244189ejb.456.2023.07.03.06.28.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 06:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bKKDW0oQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 063DE385840F for ; Mon, 3 Jul 2023 13:28:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 063DE385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688390882; bh=xbEj5XSHLcNxR8Ea9Dhk6Abpk1RWxhSfq4D6WHBVmGY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bKKDW0oQ5eflCZ72PXrDThvEJPkFe290B957SXIjYkEjfOVK9uymVzktM5r/DcJ25 zXEiHIdkNiVVzbpymILhaI2VQASE9tQxzXYcnFlZP9KOD/4UKrpda3J4YxZPYuIKj/ ByPmAJl/9xtbaBXaVclFIIFL4W9mT1ILkz4oZS7E= 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 35C983858D32 for ; Mon, 3 Jul 2023 13:27:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35C983858D32 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbc63c2e84so40986065e9.3 for ; Mon, 03 Jul 2023 06:27:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688390834; x=1690982834; 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=xbEj5XSHLcNxR8Ea9Dhk6Abpk1RWxhSfq4D6WHBVmGY=; b=UnWl7mLJEK9LXwpMx/lJ+s6k+t/aePE8E7XaC/nsgpS8leD6Xk+XRXGHCMA3RgdzTW WELQbFpHjn89CafnACDkh7l8fZiwCoJD9UMze8NceMoTdlqdx/9rUYyXX3ckzTswr0o6 CuvWZ4UafuCZcyYF6LdC/xpS0fwXxcibwGXWPlIKo5EkICSqlfq3CJWTRvhr8UzX6C28 Nq5SZG471BK0EmvIxtlTDlQNHcGgvSXJJe97/h1WbXI5zllYqrwnFBLRQu4yAfI6Nj3b XnIPpm3bJYliREJManUJvB4UfIvgXY8HI/FaDLpnGRwhIBmqOgiEXLYi0wzAxDYCDtZO trwQ== X-Gm-Message-State: AC+VfDySJY7wJubBVz8+2HFUpBRgmCrJKkrJkbUSaARI5BJ46EoI9llY msxjUsux8V2HeXL60epCetYM1NdKHzqKt7rPS7RwKg== X-Received: by 2002:a05:600c:21d1:b0:3fb:aadb:5466 with SMTP id x17-20020a05600c21d100b003fbaadb5466mr8527044wmj.33.1688390833871; Mon, 03 Jul 2023 06:27:13 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:b3e5:da4f:72d8:3c]) by smtp.gmail.com with ESMTPSA id q20-20020a1cf314000000b003f90b9b2c31sm30260901wmq.28.2023.07.03.06.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 06:27:13 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix discrepancy in expansion of untagged record equality Date: Mon, 3 Jul 2023 15:27:12 +0200 Message-Id: <20230703132712.881166-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 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, KAM_ASCII_DIVIDERS, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770406166451441816?= X-GMAIL-MSGID: =?utf-8?q?1770406166451441816?= From: Eric Botcazou The expansion of the predefined equality operator for untagged record types can be done either in line, i.e. into the component-wise comparison of the operands, or out of line, i.e. into a call to a function implementing this comparison, and the heuristics of the selection are essentially based on the complexity of the implementation. For discriminated record types with a variant part, which comprise unchecked union types, the expansion is always done out of line. For nondiscriminated types, the expansion is done in line, unless one of the components is of a record type for which a user-defined equality operator exists, in which case the expansion is done out of line. For the third case, i.e. discriminated record types without a variant part, the expansion is always done in line. Now given that the discriminants are considered as mere components for the purpose of predefined equality in this case, there does not seem to be any reason for treating it differently from the second case above. gcc/ada/ * exp_ch3.adb (Build_Untagged_Equality): Rename into... (Build_Untagged_Record_Equality): ...this. (Expand_Freeze_Record_Type): Adjust to above renaming and invoke the procedure also for discriminated types without a variant part. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch3.adb | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index 7ac4680b395..463b77fae67 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -139,7 +139,7 @@ package body Exp_Ch3 is -- the code expansion for controlled components (when control actions -- are active) can lead to very large blocks that GCC handles poorly. - procedure Build_Untagged_Equality (Typ : Entity_Id); + procedure Build_Untagged_Record_Equality (Typ : Entity_Id); -- AI05-0123: Equality on untagged records composes. This procedure -- builds the equality routine for an untagged record that has components -- of a record type that has user-defined primitive equality operations. @@ -4450,11 +4450,11 @@ package body Exp_Ch3 is Set_Is_Pure (Proc_Name); end Build_Slice_Assignment; - ----------------------------- - -- Build_Untagged_Equality -- - ----------------------------- + ------------------------------------ + -- Build_Untagged_Record_Equality -- + ------------------------------------ - procedure Build_Untagged_Equality (Typ : Entity_Id) is + procedure Build_Untagged_Record_Equality (Typ : Entity_Id) is Build_Eq : Boolean; Comp : Entity_Id; Decl : Node_Id; @@ -4481,7 +4481,7 @@ package body Exp_Ch3 is end if; end User_Defined_Eq; - -- Start of processing for Build_Untagged_Equality + -- Start of processing for Build_Untagged_Record_Equality begin -- If a record component has a primitive equality operation, we must @@ -4558,7 +4558,7 @@ package body Exp_Ch3 is Set_Is_Public (Op); end if; end if; - end Build_Untagged_Equality; + end Build_Untagged_Record_Equality; ----------------------------------- -- Build_Variant_Record_Equality -- @@ -5803,25 +5803,18 @@ package body Exp_Ch3 is end if; -- In the untagged case, ever since Ada 83 an equality function must - -- be provided for variant records that are not unchecked unions. - -- In Ada 2012 the equality function composes, and thus must be built - -- explicitly just as for tagged records. + -- be provided for variant records that are not unchecked unions. elsif Has_Discriminants (Typ) and then not Is_Limited_Type (Typ) + and then Present (Component_List (Type_Definition (Typ_Decl))) + and then + Present (Variant_Part (Component_List (Type_Definition (Typ_Decl)))) then - declare - Comps : constant Node_Id := - Component_List (Type_Definition (Typ_Decl)); - begin - if Present (Comps) - and then Present (Variant_Part (Comps)) - then - Build_Variant_Record_Equality (Typ); - end if; - end; + Build_Variant_Record_Equality (Typ); - -- Otherwise create primitive equality operation (AI05-0123) + -- In Ada 2012 the equality function composes, and thus must be built + -- explicitly just as for tagged records. -- This is done unconditionally to ensure that tools can be linked -- properly with user programs compiled with older language versions. @@ -5832,7 +5825,7 @@ package body Exp_Ch3 is and then Convention (Typ) = Convention_Ada and then not Is_Limited_Type (Typ) then - Build_Untagged_Equality (Typ); + Build_Untagged_Record_Equality (Typ); end if; -- Before building the record initialization procedure, if we are @@ -5841,9 +5834,7 @@ package body Exp_Ch3 is -- type and the concurrent record value type. See the section "Handling -- of Discriminants" in the Einfo spec for details. - if Is_Concurrent_Record_Type (Typ) - and then Has_Discriminants (Typ) - then + if Is_Concurrent_Record_Type (Typ) and then Has_Discriminants (Typ) then declare Ctyp : constant Entity_Id := Corresponding_Concurrent_Type (Typ);