From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso56137045e9.1 for ; Tue, 11 Jul 2023 02:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1689067559; x=1691659559; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lobXodaSbT+NzAVHEnZm7oTrzp1pxd+UfZjpFbOyzVo=; b=TofRCwTzViCYEvCe1FhsP0FpSgA+HcxeMXwAiXOw3+41flXc05DV7Q8R62yPQ+q1WP 62jBK0CndwWnonWnT1IXyI3mt6i1feJ1KUrAs8CgAS17xjv5hPMmgFH/D056Tg9O+8js g16EMjTTATK4+792CLjdypa1Vc9BpLMZo/sYjWQWGsqOtl7J3ynvYNcK6w4GPdbRcoC1 qmBTPYRY5VfU4VxLa9uEXElwFmUuybMGicUK5Su2m23vpjzkQ1tkgGeN4wHeqmNMQAIp oy/4JwaXN48HypXe0Ftfsxi4IqSxPqNh5k80ql582g/LLcd2kpYLwR0H7sREqxYEz8dV Qi2g== 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-Google-Smtp-Source: APBJJlE1z/guvtTJ8YCzjXeBfzhKgb0ikJNGCytFKPNuA5bQ1vDgPS9pkGFTC8Cdvpmhuh9GMqOfvw== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.40.0