From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 317B73849ACE for ; Tue, 7 May 2024 07:59:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 317B73849ACE 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 317B73849ACE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715068804; cv=none; b=wy/Y7U2zEiCCEA8FSI7XBw6jVnnjxVkmDrzIl3YvKyK3iIDTwBOcqCG0cywsXA2+krxwwKTwLrAbwrGuLP/GDRutmcXVlo+Xzo0cgia6WaB7Mam3B5urJ/BPkafuj63DC2UdciV78/2wyZzkI8gl3fGQYzx79clOom+yt5LI148= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715068804; c=relaxed/simple; bh=8w6o9pe1COkTlIX0/3TPiddA0n5WRe+LSjkowDITycc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nvzqfxy1GIb3aQfdCcXa0t/GWMHkOzUqFa6BC1T2eukpH/gG+gMIQ/N224Qm6kDtR+zw0hiWbO0WFwXWJM3LnvgCGwaAg+WxOeuXxLA1RSxY180zWsvc9I6JqqTct425EenYEFyPDlzP3HnFDBHtk5ZxJsHSYcwIHP9wxUMhA3w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e0933d3b5fso36095341fa.2 for ; Tue, 07 May 2024 00:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715068798; x=1715673598; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2ohvKQutjkLSaXd7jsq9h0Zt+4S28cABRvysbdOveVI=; b=Hd/VXvcx0k/IDE+MWkKzoA3uLsIStApkYCcNk+GinKxCVNKgDBk4zdEdain/r5dOwL eZ8AXNA42mjSFHhH39knP4+pd33f8oY9+V1pgnVKKYiAVXfH6xvL9jUNXDe5+ZctK6db G8izMawKftzjamJyuUcmEJtSRR6cwadzEXO9Zvj+94vX1i2PlOPPIM842Q2MEyins/H0 0pY7Gp+ZWtZcqu09afiD4Xp7rYPvwGqOl5TZY+MrC6jWKDAERdwPF2mNwPz/qX3M4FgF aX2bMABDZpFdOIvwY2vaz5vWl7lVrS5+fJnNDZ04P0LdiXc4F6Ii6zEjK9Bc8qzw9BSf DKtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715068798; x=1715673598; 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=2ohvKQutjkLSaXd7jsq9h0Zt+4S28cABRvysbdOveVI=; b=dEekmvIIDxMxEM/RjsAJIpAHxbsxytBLtbohn4b/jsWSPdl7F1kgHb7EC8Mh7TjcG6 lwdmjQr2tGcf+b5+BG8nkvMzj4jxV8A+Z0QzkVnraVdnPuo0xpswezKpQpv5pr6e1uQe Q1ufQu0BzecdL2M5qLXqj0PFUmnRA1WOqhZEwYc9tAzavNGoiE7TMcMNjOGfCS16ppa7 d0kW4n9ev/COLSgP5tqXP4/pFmrc8BXWQb88iMtRTRSeb7itIimVN1pdFFn8lw+WjzKa GD9Szv8ySG84wkBT18XuxkKz153Gqmg9XH9H0Oog+5dD2lZLh1zOmjoPZt+Pj/FA/k/t jcow== X-Gm-Message-State: AOJu0YxNYZmcZJNrjhLs/i+MwMwLumG3O0n+sLpJzrY3pUGdb8br1RXt qcSKrC7i6OBRCeCTdYjSSgHLetSq64dUGiTtwCwaM7ewbYwf9niow/9OVnlfdtRracH6/Zftyho = X-Google-Smtp-Source: AGHT+IHks2PQWo8k8b/j+O+HjoaJVD14LTpp2wrPF7RMBZqtdo/QZhARrHtMIfxhl5TYbsoW1g84aw== X-Received: by 2002:a2e:b889:0:b0:2df:6cb8:c911 with SMTP id r9-20020a2eb889000000b002df6cb8c911mr9058760ljp.24.1715068798191; Tue, 07 May 2024 00:59:58 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:11a6:1c9d:5099:b1e8]) by smtp.gmail.com with ESMTPSA id l8-20020a05600c4f0800b0041bfa349cadsm22291364wmq.16.2024.05.07.00.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 00:59:57 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: Fix bug in overloaded selected_components in aspect_specifications Date: Tue, 7 May 2024 09:59:56 +0200 Message-ID: <20240507075956.36643-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 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 List-Id: From: Bob Duff 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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); -- 2.43.2