From patchwork Mon May 9 09:30:26 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: 53634 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCE05384B077 for ; Mon, 9 May 2022 09:44:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCE05384B077 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652089487; bh=vvcuKJH3mcv6MRQfAAArTqZJ3sySx2d/7bsQBpHWur4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BIkEL0ednsTRQ4Q4isr2P5yTtHjCKIleusVJpC8tK0A5L5FJpDFVap2gRssWiFgpu IAfvt7KCFF3Uy84osHV3+aDoczc+VS18zyXrphm1Sd9RcgbK12D2gZsBVrJhF/H+lO fvICPjTQjJqcNLm8YPZBDdZz7zzDvg3yOtLqEYwU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id DC9D63853804 for ; Mon, 9 May 2022 09:30:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC9D63853804 Received: by mail-wr1-x431.google.com with SMTP id b19so18538840wrh.11 for ; Mon, 09 May 2022 02:30:27 -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=vvcuKJH3mcv6MRQfAAArTqZJ3sySx2d/7bsQBpHWur4=; b=cHBrv5suxPVAWr6p7HjJBKaDYBqmYmPIcnCebAGJ6IaHPfIBZuFPuaCM2PJqtmSb/g w9ZhHOvFS79EnaRDpOESO3kh0pIdEbPFYRxHXkMNB3hxCQZcNGykX2RhMCdndZV3AZgZ hJt2kom9uzElpg02qajhcJqZfngtj1cw9vFmrw3782yOn4hD5uXU9/nEQBAu1032L+BE 8L6vnbfPd2PFaZHjOmMp+U/R47zvMHhOe/FeznLXiEyZyrwcJ8pydofdQjjUUmeInDo/ 0ECn3/noYY2M5RH9WR4i809UYATWsFnwoi8L7ezPFDk8pyWm+LlqAQ+QP6aLzBg1rt2L UeIA== X-Gm-Message-State: AOAM53244OwcyQLuo2RatACTnEriIKEh/qJQ4y9XDoCSbHeSGnletS+S kv1iH0xrXJteku26aPOD3y4aNMQ4FAI55Q== X-Google-Smtp-Source: ABdhPJzWnlzh3tleT3eW4hK0lpv2LWfOZoBK+egkZbOk3k/6llIlOQyNHu00yemUbhu09u7sUFUqow== X-Received: by 2002:adf:e646:0:b0:20a:c4fa:4991 with SMTP id b6-20020adfe646000000b0020ac4fa4991mr12820224wrn.413.1652088627443; Mon, 09 May 2022 02:30:27 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id g6-20020a056000118600b0020c5253d8d6sm10727885wrx.34.2022.05.09.02.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:30:26 -0700 (PDT) Date: Mon, 9 May 2022 09:30:26 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Properly handle unprefixed references to components Message-ID: <20220509093026.GA3184372@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Steve Baird Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" In some cases, the compiler would incorrectly reject unprefixed uses of component names in an aspect specification for the composite type. Correct this error. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Replace_Type_Ref): In the case of an identifier that names a component of the type, simplify the test to decide whether to build a prefix for it (the prefix denotes the current instance of the enclosing type): if the identifier doesn't already have a prefix, then give it one. This isn't quite right in the corner case of a quantified expression or some other such expression that declares an object with the same name as a component, but it is still an improvement. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -15176,27 +15176,26 @@ package body Sem_Ch13 is end if; -- The components of the type are directly visible and can - -- be referenced without a prefix. - - if Nkind (Parent (N)) = N_Selected_Component then - null; - - -- In expression C (I), C may be a directly visible function - -- or a visible component that has an array type. Disambiguate - -- by examining the component type. + -- be referenced in the source code without a prefix. + -- If a name denoting a component doesn't already have a + -- prefix, then normalize it by adding a reference to the + -- current instance of the type as a prefix. + -- + -- This isn't right in the pathological corner case of an + -- object-declaring expression (e.g., a quantified expression + -- or a declare expression) that declares an object with the + -- same name as a visible component declaration, thereby hiding + -- the component within that expression. For example, given a + -- record with a Boolean component "C" and a dynamic predicate + -- "C = (for some C in Character => Some_Function (C))", only + -- the first of the two uses of C should have a prefix added + -- here; instead, both will get prefixes. - elsif Nkind (Parent (N)) = N_Indexed_Component - and then N = Prefix (Parent (N)) + if Nkind (Parent (N)) /= N_Selected_Component + or else N /= Selector_Name (Parent (N)) then Comp := Visible_Component (Chars (N)); - if Present (Comp) and then Is_Array_Type (Etype (Comp)) then - Add_Prefix (N, Comp); - end if; - - else - Comp := Visible_Component (Chars (N)); - if Present (Comp) then Add_Prefix (N, Comp); end if;