From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 8AC9C3858CDA; Tue, 7 May 2024 07:58:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AC9C3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715068736; bh=u6VVOIwxDPSMKqWQxjXoKLJ6trXehY2P9xf0WBM28HY=; h=From:To:Subject:Date:From; b=bMdYPKdbPJFtzW7+NwMW4lJBrRxnmw8PVA0jPeall4CAe9v/YZ2ZRFJ8oloMBBOuG urn22gZAympo/UTttpaJegC6/PvnkvOOhXYmiHcRVAipqGAzBKdl9Sh6bAITOaVk2P nMETnhZwXiA0+8eEwLoizYDed2dcUFY2TyVYZybM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r15-242] ada: Fix bug in overloaded selected_components in aspect_specifications X-Act-Checkin: gcc X-Git-Author: Bob Duff X-Git-Refname: refs/heads/master X-Git-Oldrev: 6fa5f50897c4beba0b55f0c0b76529758a5d24bd X-Git-Newrev: d4b41cc4b02e365fc749dc90975af4d2360a8fb3 Message-Id: <20240507075856.8AC9C3858CDA@sourceware.org> Date: Tue, 7 May 2024 07:58:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d4b41cc4b02e365fc749dc90975af4d2360a8fb3 commit r15-242-gd4b41cc4b02e365fc749dc90975af4d2360a8fb3 Author: Bob Duff Date: Fri Jan 5 10:40:00 2024 -0500 ada: Fix bug in overloaded selected_components in aspect_specifications This patch fixes a bug where if a selected_component X.Y appears in an aspect_specification, and there are two or more overloaded Y's in X, then it can choose the wrong one, leading to subsequent type errors. It was always picking the last declaration of Y, and leaving Entity set to that. We now reset Entity (as for the already-existing code for N_Identifier just below). Note that Resolve_Aspect_Expressions is called only for aspect_specifications, and not even all aspect_specifications, so the bug didn't occur for other names. For example, Resolve_Aspect_Expressions is not called for aspect_specifications in the visible part of a library package if there is no private part. gcc/ada/ * sem_ch13.adb (Resolve_Name): This is called only for names in aspect_specifications. If the name is an overloaded selected_component, reset the Entity. Note that this was already done for N_Identifier in the code just below. Diff: --- gcc/ada/sem_ch13.adb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index ed0e61bd7b2..c16a7710594 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -15925,12 +15925,20 @@ package body Sem_Ch13 is and then Chars (Prefix (N)) /= Chars (E) then Find_Selected_Component (N); + + -- Reset the Entity if N is overloaded since the entity might + -- not be the correct one; allow later resolution to set it + -- properly. + + if Is_Overloaded (N) then + Set_Entity (N, Empty); + end if; end if; return Skip; - -- Resolve identifiers that are not selectors in parameter - -- associations (these are never resolved by visibility). + -- Resolve identifiers, but not selectors in parameter associations; + -- the selectors are never resolved by visibility. elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) @@ -15939,8 +15947,7 @@ package body Sem_Ch13 is then Find_Direct_Name (N); - -- Reset the Entity if N is overloaded since the entity may not - -- be the correct one. + -- Reset the Entity as above for selected_components if Is_Overloaded (N) then Set_Entity (N, Empty);