From patchwork Tue May 16 08:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 94534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp274319vqo; Tue, 16 May 2023 01:52:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XHN+DJr9bNlXQzzAXHyKH6aPhGxh89bhobQsxCL2bSmtC8HP8CWvaa9Bm2KxDDkxUE0GJ X-Received: by 2002:a17:907:94d0:b0:96a:26af:b67e with SMTP id dn16-20020a17090794d000b0096a26afb67emr22069863ejc.2.1684227148125; Tue, 16 May 2023 01:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684227148; cv=none; d=google.com; s=arc-20160816; b=aQxfFZG3B4pcU0+pJaYwc1GABI/VdMToIMUwUWaE/X4jCd3tb4FsLgMELdgv82me9E eoQI8vb92ko0jJqsLxGEiZW5XxLhveRAzHM3QBjyi00pYYhhDcJ1ofbyz/kx0i7aa7vN 7ePeOboIAyK7vEEvaCr+L8rjq9lyB/4ZyPg7E0MFAqdC2Sk2HwCC5C9AHvUvpOrL6zv0 EbjicQRcEN+aCkcr5X8Vo5w4dv73r9gnKuaAps/vr3m0QX07d5S6R951hF/LQIjt21GZ /BYNVQAQAuRWGlYusFnS70qllyj6sCHs/T+MJOz/I7G3E1ySlEqiwIlV6s4gwYxW4229 o7Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=M4zE01dNW63Q1Y1k/NSnh5PV2Sw5OLjrTwP6NKoGAi8=; b=J/5SN5aX17d4xN5Nl+0RIUE3Wx1z0drRWMkMOJ/9luO2arffdDHHeZ8+ga8BU88snw ncMqjmBsW7OKmhnRDzq/UJi5D4wB4vXYP++bw4YQYsEP3u2AwrTh8fnSHKCrnRF377Am OXPTwp80LPN7n6/1v2LGqqwCP26uEO3nnDC+rjAUD5QDgjZ01NWBePG6B/18mNHAnl9D s5FtUgoLHi2nHo5e2g0yM7OwEI2lt2LjDH1uQERAToivXcTJuAurTz76K7N6jNGn+isI NGNutnJnqUYjqQx3lsnUXPkgQY6jgKceclK9qZgkuT7C0lpMSfeRg+XpTkjF9erQ6nYP 9QRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dEFHa20z; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l14-20020a170906414e00b0094f2d274b62si15841307ejk.550.2023.05.16.01.52.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:52:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dEFHa20z; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A6323888C65 for ; Tue, 16 May 2023 08:46:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A6323888C65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684226773; bh=M4zE01dNW63Q1Y1k/NSnh5PV2Sw5OLjrTwP6NKoGAi8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dEFHa20zKtxKfLEggOGIJFqgbelvtFutp+Q4rrEJmZvzwPOnueYFRaIzxLyMN8aGH 3iWQOYCdP0ktLWYNiiY+GW7749UbflKXdh1610dSgGsyxIXmGR+qeDaP/01Y6S3GJt zy9aaid/DJPtQUxHM0rt5fWSuynOIHyW0L4RbxxM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 716F33856DE8 for ; Tue, 16 May 2023 08:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 716F33856DE8 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f475366522so44890165e9.1 for ; Tue, 16 May 2023 01:41:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684226472; x=1686818472; 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=M4zE01dNW63Q1Y1k/NSnh5PV2Sw5OLjrTwP6NKoGAi8=; b=hvJSqXPaFyfjtz6rkVoz7CjgHMMJeSnwDLLCg+73bMnLyMHphTwZOZxCeTGglmwbR9 MdhhiT2H/e7lYUkSSu4ERT3lzdJcESjmvU7VxL6WkPveQCzTnyPTYTA7v4MinvxbXcIW zE+hqmOqJdx1yQ+KG+MI8xVw5WIuPufrvpCCU5rrc7DsYKcNv1GMVRWwIBgl8HzvAkkO obFKaAzkdGvN8LWiEUfQqzguqxXmDsPxH6221Ju98f7gxLNyea+QN0rs4NTYYxfTiacq Ca/olxisGpXUsav9CiaIyqyxa3jx7nGor6JkEoML5xoREXcxMrZSk8wQawAMMmhVjpUT fFjg== X-Gm-Message-State: AC+VfDw4iSD7rc0FONHB+gUza170TEGiJBJi7SFars6K1XM6Yd94E3SK B/V10/AeZJKS0m0tIFWWvPLToSCpX23RY/u7IqcnMQ== X-Received: by 2002:a7b:cb07:0:b0:3f1:7972:429d with SMTP id u7-20020a7bcb07000000b003f17972429dmr25305565wmj.18.1684226472274; Tue, 16 May 2023 01:41:12 -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 j15-20020a05600c1c0f00b003f1738d0d13sm32100395wms.1.2023.05.16.01.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:41:11 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Spurious error analyzing 'old or 'result in class-wide conditions Date: Tue, 16 May 2023 10:41:10 +0200 Message-Id: <20230516084110.1502069-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766040166075492006?= X-GMAIL-MSGID: =?utf-8?q?1766040166075492006?= From: Javier Miranda gcc/ada/ * sem_attr.adb (Analyze_Attribute_Old_Result): When preanalyzing a class-wide condition, search in the scopes stack for the subprogram that has the condition. This is required because returning the current scope causes reporting spurious errors when the occurrence of the attribute is found, for example, in a quantified expression. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 452aabdd436..a07e91b839d 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -1366,8 +1366,27 @@ package body Sem_Attr is -- yet on its definite context. if Inside_Class_Condition_Preanalysis then - Legal := True; - Spec_Id := Current_Scope; + Legal := True; + + -- Search for the subprogram that has this class-wide condition; + -- required to avoid reporting spurious errors since the current + -- scope may not be appropriate because the attribute may be + -- referenced from the inner scope of, for example, quantified + -- expressions. + + -- Although the expression is not installed on its definite + -- context, we know that the subprogram has been placed in the + -- scope stack by Preanalyze_Condition; we also know that it is + -- not a generic subprogram since class-wide pre/postconditions + -- can only be applied for primitive operations of tagged types. + + if Is_Subprogram (Current_Scope) then + Spec_Id := Current_Scope; + else + Spec_Id := Enclosing_Subprogram (Current_Scope); + end if; + + pragma Assert (Is_Dispatching_Operation (Spec_Id)); return; end if;