From patchwork Wed Jul 6 13:31:29 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: 1652994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CIfxhvuT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LdLBF0fSdz9s07 for ; Wed, 6 Jul 2022 23:34:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E54AB3834E57 for ; Wed, 6 Jul 2022 13:34:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E54AB3834E57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657114482; bh=sAlxboQdw1mHVSjWbDl+6oN2NuPRcAI26SVqmgZeumw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CIfxhvuTvK5wYw3SN32OKage0wZY0c9kZMDWvOprlqk5KvJbqBNnM+6iGWDC+7Nx+ NYy/nOJDojV/r/VbNMM1I7XTnFiERkpFG8nCQSz+Zsk8nbxyoQViT6jX3ASAnwtaPs x3l5ieMMPcvbXo1cIn7B0tuj4tvzEy5D3LUje9PE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 9B74D3857C5B for ; Wed, 6 Jul 2022 13:31:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B74D3857C5B Received: by mail-wr1-x42b.google.com with SMTP id v16so10652908wrd.13 for ; Wed, 06 Jul 2022 06:31:31 -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=sAlxboQdw1mHVSjWbDl+6oN2NuPRcAI26SVqmgZeumw=; b=pVOhD1oxpY2hIE8rqg5DxmOvdsGGpfI19H5DPaWtxbAUbsBHxteiEQWpG3CrTkx7vE sVSlBTPEOW1z63j/aah8pTrefBeGljlsBUYWjqOt9Wy8mz4uEcsE9RAiSVSFVPXLXed0 AXqbfR8b9SdPNlRFsz7Xsl9kIPBl2nTn3Rcr6UxOPnE2rs2He2dqBCNfnfSnN5oMjlnd 5DjQkj6JxoqCfd5rzv6lyN43k/FrnBiTvUJg2GPJYSPmctMeD6CFVLVN2u075A5wCB5h pI4psigAeP/JU5RaN0u4XAH4pr904sk8ZqXKw51DaGylKjcRvcb0pWHyElUsnQneDHV9 sOFA== X-Gm-Message-State: AJIora998JczOG+HqAKTmXZ9kP7baPpTzFdW0oKh6Lkuu/ZjQI3vg7as Kdp0xRavA3CpCuXsxkkUmR4e8pKWSK+Exw== X-Google-Smtp-Source: AGRyM1v1Mo8C1759JHdTC7MKk9bKQAQQOMc/TJO9/zbKyZEhPOydyVEnopvYl/qeJpetvqjdkRRAqQ== X-Received: by 2002:a5d:6e5c:0:b0:21d:7ba1:3601 with SMTP id j28-20020a5d6e5c000000b0021d7ba13601mr3860889wrz.554.1657114290481; Wed, 06 Jul 2022 06:31:30 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id b4-20020a5d6344000000b0021d68a504cbsm9695462wrw.94.2022.07.06.06.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 06:31:29 -0700 (PDT) Date: Wed, 6 Jul 2022 13:31:29 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Spurious non-callable warning on prefixed call in class condition Message-ID: <20220706133129.GA2205455@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch corrects an error in the compiler whereby a function call in prefix notation within a class condition causes a spurious error claiming the name in the call is a non-callable entity when there exists a type extension in the same unit extended with a component featuring the same name as the function in question. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Analyze_Selected_Component): Add condition to avoid interpreting derived type components as candidates for selected components in preanalysis of inherited class conditions. diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -5158,11 +5158,26 @@ package body Sem_Ch4 is elsif Is_Record_Type (Prefix_Type) then - -- Find component with given name. In an instance, if the node is - -- known as a prefixed call, do not examine components whose - -- visibility may be accidental. + -- Find a component with the given name. If the node is a prefixed + -- call, do not examine components whose visibility may be + -- accidental. - while Present (Comp) and then not Is_Prefixed_Call (N) loop + while Present (Comp) + and then not Is_Prefixed_Call (N) + + -- When the selector has been resolved to a function then we may be + -- looking at a prefixed call which has been preanalyzed already as + -- part of a class condition. In such cases it is possible for a + -- derived type to declare a component which has the same name as + -- a primitive used in a parent's class condition. + + -- Avoid seeing components as possible interpretations of the + -- selected component when this is true. + + and then not (Inside_Class_Condition_Preanalysis + and then Present (Entity (Sel)) + and then Ekind (Entity (Sel)) = E_Function) + loop if Chars (Comp) = Chars (Sel) and then Is_Visible_Component (Comp, N) then