From patchwork Thu Jun 20 08:53:13 2024 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: 1950017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=hswNIu85; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W4Zbw6jDDz20X6 for ; Thu, 20 Jun 2024 19:16:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B14DD3891C3B for ; Thu, 20 Jun 2024 09:16:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 6D8AF388982E for ; Thu, 20 Jun 2024 08:53:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D8AF388982E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6D8AF388982E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873641; cv=none; b=VzyHoPoBlYfCY2TXEDOGF3jAkP4HwZlBXl/Qs1/rRe3B69yImQ/19VAEAydE9Xs0cm5UIc9J0DzC2LDPxLBok194LxztZz9mnfdaiY7h4BgemCF/8TuoT0QNQNpT5dJ/QOlZ1RjVepVNd9bRcASgcOr2BiuzEB278MdYTLkLpiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873641; c=relaxed/simple; bh=z6yLKaIW0QRrKecArdH15NY9+LQLzp0QnHmLd4bzsxI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=x1NgwjmwV47UlZAk3yO4ma8+ekS/Uv8swi7rvIewOTT1zd/up1iQRzf3ffu8H+iCv1i742ZYUUh//pHc3nSd7j4HgSc+CD3No4OY2gslv4+V4cPc1LCP1tHRDs7pkQNOOxX8bYa8BrEL4CXWWfRXEYbTMgzg2kzXvp84wcbMwAE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-364a3d5d901so456365f8f.0 for ; Thu, 20 Jun 2024 01:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718873632; x=1719478432; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3wYe8qVNdL+9S9b9xHS7mpQVKVRRGSKYAhkJta5pw/M=; b=hswNIu85pzKBCLaEsCEtTFHMG7uD/3YvUy7SFGWBiQN+m9GlczoDvlcZL3N+xTuj/x u1n9++U3p0rXrgrYhneuGLBkXpQXWx07+IMU4mhem6HVPs6rAn/SA0dZs9uBFeUNEttV BHf5WGkTywnMe4MQBzYW6fjFLmkR4o6gtc7ck7kOuNM6ZJ2xbaHOjr8T1GJcCaWeP80K YVC+wzPFclBnqrRUK1QJT0PrzwXhwTK7z++H0lLoG/FXP6AkGxUKNHGjvUEz0DgdXkFp R1UQVhuL/japFzyGHYm0aWKz/5B8UX5i6D+BsbgSb7gsA18Te6XhPRoQ2BwbjVhgcheY ho3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873632; x=1719478432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3wYe8qVNdL+9S9b9xHS7mpQVKVRRGSKYAhkJta5pw/M=; b=KrrB/kKcNLCfpE725KlI/DACNoSAa2d0WzFAAkqyDrdYMsYZVUwWj/QOkvgq8KsS+D wYbv0mOxuEY9udNf5l2p4xUnFM13Cy/forl9HKX2Bx1uaOu8cGclDO1k+QwNJonE5ZIa dZZ6ZWofoE7i4aJxY1YMoFLcEYocXW4YSlHAedTbBltW+ACURC2y+BYV1MckzpC48uqE v65a7f09m50Ktli7Xf4uokjjwi90Lfc1/26BxtH5sM1ukcnF21/QTCeDIjFhGY+338/g HDZhfGW9jUb3sx0jgiqjcoxFd5mvEo0Ho20nCxA1pxOmoChtYu342yBESNF5YEydBfcR uzLg== X-Gm-Message-State: AOJu0YzyZ0qO6DKujLz8LUvbOjEaAISq0R483ZwnUVJwBvJmVSZ1O1CP 4ZUlJ/t6y1el5MTJaQwV3m9ih+pIgAl69ytLxNmprT4EmsRq/Y+8vCvNu/M40zgVVUOyB76CbCU = X-Google-Smtp-Source: AGHT+IHAVhQZ6tnrRxZEnG0Ha+epkxztbrMVoKvWGjepIV63UYsRXQibhRsfLDVKk6MqrOnI54zKnw== X-Received: by 2002:adf:fdd0:0:b0:35f:24e6:78bd with SMTP id ffacd0b85a97d-36317b7d444mr3435482f8f.33.1718873632014; Thu, 20 Jun 2024 01:53:52 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-363c795febfsm3305522f8f.104.2024.06.20.01.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 01:53:51 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 23/30] ada: Fix composition of primitive equality for untagged records with variant part Date: Thu, 20 Jun 2024 10:53:13 +0200 Message-ID: <20240620085321.2412421-23-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620085321.2412421-1-poulhies@adacore.com> References: <20240620085321.2412421-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Eric Botcazou In Ada 2012, primitive equality operators of untagged record types compose like those of tagged record types, but this has never been implemented for untagged record types with a variant part. gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): In the untagged record case, always look for a user-defined equality operator in Ada 2012. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 50 ++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 983f66231a2..1674d6c8132 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -2329,6 +2329,28 @@ package body Exp_Ch4 is -- Case of untagged record types elsif Is_Record_Type (Full_Type) then + -- Equality composes in Ada 2012 for untagged record types. It also + -- composes for bounded strings, because they are part of the + -- predefined environment (see 4.5.2(32.1/1)). We could make it + -- compose for bounded strings by making them tagged, or by making + -- sure all subcomponents are set to the same value, even when not + -- used. Instead, we have this special case in the compiler, because + -- it's more efficient. + + if Ada_Version >= Ada_2012 or else Is_Bounded_String (Comp_Type) then + declare + Eq_Call : constant Node_Id := + Build_Eq_Call (Comp_Type, Loc, Lhs, Rhs); + + begin + if Present (Eq_Call) then + return Eq_Call; + end if; + end; + end if; + + -- Check whether a TSS has been created for the type + Eq_Op := TSS (Full_Type, TSS_Composite_Equality); if Present (Eq_Op) then @@ -2355,34 +2377,6 @@ package body Exp_Ch4 is Parameter_Associations => New_List (L_Exp, R_Exp)); end; - -- Equality composes in Ada 2012 for untagged record types. It also - -- composes for bounded strings, because they are part of the - -- predefined environment (see 4.5.2(32.1/1)). We could make it - -- compose for bounded strings by making them tagged, or by making - -- sure all subcomponents are set to the same value, even when not - -- used. Instead, we have this special case in the compiler, because - -- it's more efficient. - - elsif Ada_Version >= Ada_2012 or else Is_Bounded_String (Comp_Type) - then - -- If no TSS has been created for the type, check whether there is - -- a primitive equality declared for it. - - declare - Op : constant Node_Id := - Build_Eq_Call (Comp_Type, Loc, Lhs, Rhs); - - begin - -- Use user-defined primitive if it exists, otherwise use - -- predefined equality. - - if Present (Op) then - return Op; - else - return Make_Op_Eq (Loc, Lhs, Rhs); - end if; - end; - else return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs); end if;