From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f475366522so44890165e9.1 for ; Tue, 16 May 2023 01:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684226472; x=1686818472; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M4zE01dNW63Q1Y1k/NSnh5PV2Sw5OLjrTwP6NKoGAi8=; b=eonAlwNt8+1N/y3AgYGvqUZ1dS8zJ/E8yCHirBjvbyW30CQox3aZXfzqOVAQwv90qk zQLjXIzWwCf7wMrbwX/xVdjCvSHH9Q44FoXfVOsJ80+9GqoUhNEw/g+c4z1ofdiZ/DJv NieR0pG2ZLQP9epLUnBTGDEOXkL6cIbzg04HY0nMgDwO9zepduDV9Yw1Kcf75PrQlTcC i1K0pC6LWBaLMe0D/CuAcpk4MnMdtFlMvvW6W9WbtpvbjnwxeWXvfJdYXrynzA7M5C3P b4Rd5ct7yqrJLn+Za6A6sIbYfzlNssRhpXm4m/ZOpOKfLKPAythYhYGYgBu85VhbwDAL l91g== 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-Google-Smtp-Source: ACHHUZ5iSmuhsLXmykC2PWckIUZ/5wrl85MPirtWfW/gAYNKyIawcC0tAnfvM08gwasC98sE0OEZQA== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; -- 2.40.0