From patchwork Tue Jul 11 09:25:48 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: 118349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp348767vqm; Tue, 11 Jul 2023 02:26:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGP4dPMiOskE9AKBnWgiDp6K2yCZraByK8/vrFmtKmd2FNAMr5xoJR1361AlRUyVYnmfl2b X-Received: by 2002:aa7:c7c4:0:b0:51e:7c:5025 with SMTP id o4-20020aa7c7c4000000b0051e007c5025mr12805822eds.9.1689067614958; Tue, 11 Jul 2023 02:26:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689067614; cv=none; d=google.com; s=arc-20160816; b=ddhG2Era9YWYZcFbFPFcDnoREtIE5KGcv0MEtnXM76LL32K5JYRR1kTl5EXOdbskz3 yoaWXm0ylo/6Ao4gMfQLoVe45IKEykX443j7CmZ4GQYzbErJGwQTO5Sk6Bn1aOzvczC0 5g7vlt4J7x5ic+gBamr+aZThrp4tnqD+rPSOWYNMSGgdF5QvT/LC0X92QjQdmmMmfED7 iGkqeh1v+CM7alwEnXn0SH/esCa5NqszR7dnpIoRHvkI1SPpNBmX/i6u6qlXPtr4Xvym vcj0sV9k1jKlue7Z0vTkCDIfVIpeBGszbNiujEm4y8g2NSpjwBx70Ws4PNiEaBHuviZs n/ng== 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=lobXodaSbT+NzAVHEnZm7oTrzp1pxd+UfZjpFbOyzVo=; fh=/3KX5nH+f3PGIzCwnuf//1E+cbLgxv/xavy4NboKqC4=; b=pMP1jAUG9mz4MKjCFqZa8Awme1JQvIwmKewbMk9kkeNrxS+MmVsppcZ736xxM8/Cdh MQ5MQLxJeDwm970iSvIASA8/xEoXl+atV4pB+xLzCG+DS6DRmzqmdWEs2cn7sOY4HIV5 rs/jc/GDtoUlmP77q14gNAqhit0VgxhZWbdk5PIuXQs122Pokq5i5WcaLgtA6KM8E1tH tG/cBO+RGs8hlruEYcKfadNkzDb0YbugECaVlnk0+Q/y1H5q9Hdl8ZK+lqnZtX0L7SVe l1lSGL2WOZdGIC7fqdiQZXf6t5/hP+or7LwwhBISpjraJ40t3MYNMW5C8H9DgqDd4s62 FDUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DpmxwVcZ; 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 r23-20020aa7c157000000b0051e2cd8f6aesi1740989edp.70.2023.07.11.02.26.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 02:26:54 -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=DpmxwVcZ; 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 ABF3D3857711 for ; Tue, 11 Jul 2023 09:26:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABF3D3857711 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689067605; bh=lobXodaSbT+NzAVHEnZm7oTrzp1pxd+UfZjpFbOyzVo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DpmxwVcZMonvbZQyUalDYBMIgZsobWhE5mLRpBV/KvZWfbJPf0ZsLAD1WQOMfBP+v 3ifB8gXmFdmAbF6Wbtcmjv7SwvGwVjaJKu5lrOzLoU8P3Ugj4VXE2I1u7d7VbN138o UXrrx4c8tMeXTvJ70ntQ5uM9rVtLU6DSCScdZGB8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 5D20D3858D20 for ; Tue, 11 Jul 2023 09:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D20D3858D20 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso56137045e9.1 for ; Tue, 11 Jul 2023 02:26:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689067559; x=1691659559; 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=lobXodaSbT+NzAVHEnZm7oTrzp1pxd+UfZjpFbOyzVo=; b=Ri6eUj5d2h7jXSWkoajImEGlLLuZnTcBmToFbaqKmmYg2zkw2Xe+Ry77ljVTkwvKKC aBj3LHBg7eVUef644Bo4Y7gBHOjlGGnVJRgKFult5nfEQzpWRmIGvtR6CKXDvbbvQdYh s+1/Xyx1KoUMH0ZEM2TG/UNDsNWwayYMcEJp9pPAtvpLLj4D/MTlYPIfCK0e+cZpuMED lLWqhM8lKRP3fJnyCcFIW+Z3qLNk1ku4JoH5+3SFAp0FbkljFZ5rYpZ3Y9I0HaEi8ba0 qfWrn3Pg7lUEG3+bzc2M/MZZyxZTLzolvKKpiHDk86BWCpo3istCMbb4h+1uyLwtlJoH Di8w== X-Gm-Message-State: ABy/qLZsElT8Pgw0BwqHQF1891L+Ig8YJpt6Rsa8s/ec4uni76EDIFYL 9RnlsQI0NkmZnvt4obI164INYokNlrAO34mewkuSHg== X-Received: by 2002:a05:600c:2153:b0:3fb:dbd0:a7ea with SMTP id v19-20020a05600c215300b003fbdbd0a7eamr13682834wml.37.1689067559076; Tue, 11 Jul 2023 02:25:59 -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 l3-20020a1ced03000000b003fc0062f0f8sm2016991wmh.9.2023.07.11.02.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 02:25:58 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix wrong resolution for hidden discriminant in predicate Date: Tue, 11 Jul 2023 11:25:48 +0200 Message-Id: <20230711092548.2323955-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 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.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: INBOX X-GMAIL-THRID: 1771115763615085400 X-GMAIL-MSGID: 1771115763615085400 From: Eric Botcazou The problem occurs for hidden discriminants of private discriminated types. gcc/ada/ * sem_ch13.adb (Replace_Type_References_Generic.Visible_Component): In the case of private discriminated types, return a discriminant only if it is listed in the discriminant part of the declaration. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch13.adb | 49 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index c3ea8d63566..4f97094aae5 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -15569,15 +15569,11 @@ package body Sem_Ch13 is function Visible_Component (Comp : Name_Id) return Entity_Id is E : Entity_Id; + begin - -- Types with nameable components are record, task, and protected - -- types, and discriminated private types. + -- Types with nameable components are record, task, protected types - if Ekind (T) in E_Record_Type - | E_Task_Type - | E_Protected_Type - or else (Is_Private_Type (T) and then Has_Discriminants (T)) - then + if Ekind (T) in E_Record_Type | E_Task_Type | E_Protected_Type then -- This is a sequential search, which seems acceptable -- efficiency-wise, given the typical size of component -- lists, protected operation lists, task item lists, and @@ -15591,6 +15587,45 @@ package body Sem_Ch13 is Next_Entity (E); end loop; + + -- Private discriminated types may have visible discriminants + + elsif Is_Private_Type (T) and then Has_Discriminants (T) then + declare + Decl : constant Node_Id := Declaration_Node (T); + Spec : constant List_Id := + Discriminant_Specifications (Original_Node (Decl)); + + Discr : Node_Id; + + begin + -- Loop over the discriminants listed in the discriminant part + -- of the private type declaration to find one with a matching + -- name; then, if it exists, return the discriminant entity of + -- the same name in the type, which is that of its full view. + + if Present (Spec) then + Discr := First (Spec); + + while Present (Discr) loop + if Chars (Defining_Identifier (Discr)) = Comp then + Discr := First_Discriminant (T); + + while Present (Discr) loop + if Chars (Discr) = Comp then + return Discr; + end if; + + Next_Discriminant (Discr); + end loop; + + pragma Assert (False); + end if; + + Next (Discr); + end loop; + end if; + end; end if; -- Nothing by that name