From patchwork Mon May 16 08:43:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1631408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=H3yCAuqc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L1tkl6pQgz9s2R for ; Mon, 16 May 2022 19:10:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1922C3857419 for ; Mon, 16 May 2022 09:10:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1922C3857419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652692222; bh=Mc3pkgAir4GFCvZ5jdFiFYBAqu1opsPjd+BvScbisO8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=H3yCAuqcz7UGExJSPQGI0vRhFf0Nu2prhzqXz0fjcMEWAON0D+fX8u4lDcPUpaWMN 7y9bG7faCvrli923lf6UUwMUCS6LnYbd9zcYAGXYg+Bn6cpjIPE6J05gsncb+b5lEx xl4VlnNvDPsC85H506Pkh8rFeFetb+1f1Bi095Sk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id B1E023857C6F for ; Mon, 16 May 2022 08:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B1E023857C6F Received: by mail-wm1-x32e.google.com with SMTP id m62so8239671wme.5 for ; Mon, 16 May 2022 01:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Mc3pkgAir4GFCvZ5jdFiFYBAqu1opsPjd+BvScbisO8=; b=oQ2Mj50DCMyNSz7lcqcPlf0eQ19XUqr6c3c9ruy6r280cs1gzUPkdoKuLMM0FlzMs3 AFLqKAXxh0eBnt8wIIjqgf5IxXI+Gbu4tfgILF4SttwRVBOdiyj6IdULVWnq6Nyhy6P0 jmYcpGZK4rnhoWIiegnut2hN7Hc645DkPrPKiq9RvA0N1W/KBB7hmgHM/bSqIRUm+mkB c+k9ZfXorwK19RFRi3ZZtI/einWHfZKXOOtitbTmuiGtEKNI6/klmHwCmQt+O4ESQ/lE lPg87B+3OyhpHZ1Kwwh1zPJOAxXuYIw5CXiF7/CkljaJjC3VcJwe6AW5CsxjzSnc+CG3 uxsA== X-Gm-Message-State: AOAM531UlqyPiI4gRzfZ7HXE4ITeZ+AuPuwYPHRuR81vtYPSmrIC5pNp obNbhJ3YvgjemLT9Tz07JHTvtsFvmTFQ2Q== X-Google-Smtp-Source: ABdhPJyJlLTIxFGwoPKv8Rrb3nhjtSfBH1h4EsJTHkw6p5BzgSMwbDj5DeWRIM8meI2ZDKuN3m8oew== X-Received: by 2002:a7b:cb84:0:b0:382:a9b9:2339 with SMTP id m4-20020a7bcb84000000b00382a9b92339mr26640948wmi.91.1652690603526; Mon, 16 May 2022 01:43:23 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id c3-20020adfc6c3000000b0020c5253d8dasm9086696wrh.38.2022.05.16.01.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 01:43:23 -0700 (PDT) Date: Mon, 16 May 2022 08:43:22 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix fallout of change in equality for untagged record types Message-ID: <20220516084322.GA3843864@adacore.com> MIME-Version: 1.0 Content-Disposition: inline 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, 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The problem is that the resolution of expanded names implicitly assumes that the visible and private homonyms in a given scope are segregated on the homonym chain, and this was no longer the case for equality operators in the specific case at stake. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch7.adb (Inspect_Untagged_Record_Completion): Also move the equality operator on the homonym chain if there is another equality operator in the private part. diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1491,6 +1491,7 @@ package body Sem_Ch7 is Prim_List : constant Elist_Id := Collect_Primitive_Operations (Defining_Identifier (Decl)); + E : Entity_Id; Ne_Id : Entity_Id; Op_Decl : Node_Id; Op_Id : Entity_Id; @@ -1517,16 +1518,39 @@ package body Sem_Ch7 is pragma Assert (Ekind (Ne_Id) = E_Function and then Corresponding_Equality (Ne_Id) = Op_Id); + E := First_Private_Entity (Id); + -- Move them from the private part of the entity list -- up to the end of the visible part of the same list. Remove_Entity (Op_Id); Remove_Entity (Ne_Id); - Link_Entities - (Prev_Entity (First_Private_Entity (Id)), Op_Id); + Link_Entities (Prev_Entity (E), Op_Id); Link_Entities (Op_Id, Ne_Id); - Link_Entities (Ne_Id, First_Private_Entity (Id)); + Link_Entities (Ne_Id, E); + + -- And if the private part contains another equality + -- operator, move the equality operator to after it + -- in the homonym chain, so that all its next homonyms + -- in the same scope, if any, also are in the visible + -- part. This is relied upon to resolve expanded names + -- in Collect_Interps for example. + + while Present (E) loop + exit when Ekind (E) = E_Function + and then Chars (E) = Name_Op_Eq; + + Next_Entity (E); + end loop; + + if Present (E) then + Remove_Homonym (Op_Id); + + Set_Homonym (Op_Id, Homonym (E)); + Set_Homonym (E, Op_Id); + end if; + exit; end if;