From patchwork Thu Sep 11 09:18:39 2025 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: 120035 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B541C3856260 for ; Thu, 11 Sep 2025 09:28:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B541C3856260 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=PgUioHc1 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 192683858C74 for ; Thu, 11 Sep 2025 09:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 192683858C74 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 192683858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582362; cv=none; b=RJ1qKUe9IEgfzmTaY4Sg6X/yioKXFdc/eULkmK4xnSS7QFEJ+d9SH8yxf/yf0MQLQUNj8aiBk9M/TduAWlwvqRYrnxlk8M88QFU52r8S0Mzo2jgrjt/6Z/wbW80mCJN38WJQ6WcWXu6pFOdXKfgYH/sBfE/+rfQic7o2kDpf3WE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582362; c=relaxed/simple; bh=UPfeXmpc7iP4kHmw4DNCuPMq7L98KbKEr7hdgUlhpOk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i+cD+UtvSWG+6g48FjeRvwE1JPsdYYSLTefwxBSaL+0UIzrHjD2SuvfqyYVfoZIdDNluPDPDPA428Ov4XpB0k5FBgc0Pel341iwECIZ6OivX4MbyS5I5Zh8mF9wDnHQpe/x6Lur0W8Pa1GAFK6TcIYasLtDDfp/91sxOAAZlQWg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 192683858C74 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3dae49b1293so278262f8f.1 for ; Thu, 11 Sep 2025 02:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582361; x=1758187161; 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=3Mx9ZjJdYkMPIDvUpLVslPQvvU+9sJiQZmRstLgQMaU=; b=PgUioHc16TEQQWhLjrket+lH3icbNv6KlpicnsV/OSJEMkZz7DATdx0oBY7gV02sXe X6bCnhzy2ANAZys5QaSf29HAUwHzf6RAxvEGx+1X8Nf5Tkx7RvJ5qK5maWLMdk592TUp 2IG+h1ljxHET86sMr6ol/DeUwEPJMmcZzwkwmiYHsiVuNNlimhhbVXziH326s8LW05yQ XTRhzIIjqJr6ma4+ZBN3Za8pN4mdbXSpVPLDxz0wIIE+8bRqjE8ycCv0cOEizvXwp5ey mXFVdHv0uxsJbjsKB/6Yn2AEW3047yGN4DQHhGIXFEAozqSGzErYIn8k6ql5lPskkdXK eQAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582361; x=1758187161; 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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AGHT+IFzO13hoTD372gSvyomL7n8atyZp+Oih5cyi3fDyvIcA8uBJg9DId4PX/4zbkuQboUjxRFyPQ== X-Received: by 2002:a05:6000:2882:b0:3dc:1473:18bd with SMTP id ffacd0b85a97d-3e636d904d8mr13499655f8f.3.1757582360740; Thu, 11 Sep 2025 02:19:20 -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-3e7607cd27dsm1649971f8f.41.2025.09.11.02.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:20 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED 07/31] ada: Refine condition for reporting warnings on components with abstract equality Date: Thu, 11 Sep 2025 11:18:39 +0200 Message-ID: <20250911091904.1505690-7-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911091904.1505690-1-poulhies@adacore.com> References: <20250911091904.1505690-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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 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~patchwork=sourceware.org@gcc.gnu.org From: Gary Dismukes The initial implementation of the warning resulted in unwanted false positives for types that have a user-defined equality function (in which case abstract equality on components will typically not ever be invoked). The conditions for reporting the warning are refined by this change to exclude checking for presence of abstract component equality functions in the case where the containing type has a user-defined equality. gcc/ada/ChangeLog: * exp_ch4.adb (Expand_N_Op_Eq): Test for absence of user-defined equality on type being compared (for both array and record types) as a condition for checking for abstract equality on component types. Add a "???" comment about current limitations on issuing the new warning. (Warn_On_Abstract_Equality_For_Component): Remove temporary disabling of the warning. Improve comment on declaration. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 60 ++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 2ac5e797e512..23a59de6f872 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -8187,8 +8187,8 @@ package body Exp_Ch4 is procedure Warn_On_Abstract_Equality_For_Component (Comp_Type : Entity_Id); - -- If Comp_Type has a user-defined abstract equality function, then - -- issue a warning that Program_Error will be raised. + -- If Comp_Type is a record type with a user-defined abstract primitive + -- equality, then issue a warning that Program_Error will be raised. ------------------------- -- Build_Equality_Call -- @@ -8423,13 +8423,6 @@ package body Exp_Ch4 is is Eq : Entity_Id; begin - -- Temporarily disable warning, to prevent spurious warnings - -- occurring in vss-xml-implementation-html_writer_data.adb. ??? - - if True then - return; - end if; - if Is_Record_Type (Underlying_Type (Comp_Type)) then Eq := Get_User_Defined_Equality (Comp_Type); @@ -8509,7 +8502,16 @@ package body Exp_Ch4 is -- Array types elsif Is_Array_Type (Typl) then - Warn_On_Abstract_Equality_For_Component (Component_Type (Typl)); + + -- If the outer type doesn't have a user-defined equality operation, + -- check whether its component type has an abstract equality, and + -- warn if so. Such a component equality function will raise + -- Program_Error of objects of the outer type are compared using + -- predefined equality. + + if not Present (Get_User_Defined_Equality (Typl)) then + Warn_On_Abstract_Equality_For_Component (Component_Type (Typl)); + end if; -- If we are doing full validity checking, and it is possible for the -- array elements to be invalid then expand out array comparisons to @@ -8580,17 +8582,35 @@ package body Exp_Ch4 is elsif Is_Record_Type (Typl) then - declare - Comp : Entity_Id := First_Component (Typl); - begin - while Present (Comp) loop - if Chars (Comp) /= Name_uParent then - Warn_On_Abstract_Equality_For_Component (Etype (Comp)); - end if; + -- When outer type doesn't have a user-defined equality operation, + -- check whether any of its components' types have an abstract + -- equality, and warn if so. Such component equality functions will + -- raise Program_Error when objects of the outer type are compared + -- using predefined equality. - Next_Component (Comp); - end loop; - end; + -- ??? Note that this warning is currently only issued in cases of + -- top-level components of the type and not for deeper subcomponents. + -- Those could be handled with more work, such as by adding a flag + -- on record type entities, but it's not clear that it would be + -- worth the effort. Another limitation is that the warning check + -- is not done for tagged types in some cases, because equality + -- comparisons for those can be changed to calls at an earlier point + -- during analysis and resolution, and do not reach this code (but in + -- many cases tagged equality comparisons do reach the code below). + + if not Present (Get_User_Defined_Equality (Typl)) then + declare + Comp : Entity_Id := First_Component (Typl); + begin + while Present (Comp) loop + if Chars (Comp) /= Name_uParent then + Warn_On_Abstract_Equality_For_Component (Etype (Comp)); + end if; + + Next_Component (Comp); + end loop; + end; + end if; -- For tagged types, use the primitive "="