From patchwork Tue May 23 08:08:24 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: 1784948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=a90jXYIk; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QQRqc00qwz2020 for ; Tue, 23 May 2023 18:11:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F41A93858C54 for ; Tue, 23 May 2023 08:11:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F41A93858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684829514; bh=uwHW19eitu9C76klJvetEgmWnPPT7gSp/fLTRE15Q0A=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=a90jXYIkUDxunQ+l7c/u9s3hTTUpZacM+KfHdPLNMW09xxKl/69O5WESmx3gtgrxc ZctwH3JcWAKI98Ug9CCs2W9xAmdmvlky3uBrfITKHGM7ZODh1cgSyWqij8lYGqSDSA NscCDCVRZ1ij7dGet5JPPCeMPk+f5/v+JQQQ6MQc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 778123882018 for ; Tue, 23 May 2023 08:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 778123882018 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3078aa0b152so4590857f8f.3 for ; Tue, 23 May 2023 01:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829305; x=1687421305; 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=uwHW19eitu9C76klJvetEgmWnPPT7gSp/fLTRE15Q0A=; b=OPObcY9teP0sOht4YVG67GGXHcqwVMII4WjGNg4ntQ4krFbqZTPsQ5bFG4HC5HWJpw HKPwkbKc+J4Cg5wJiC0jhXdbZ3euFivjB+RCAqpS+9+FBPR0izeGgBVNvPSMzB2ja61u armV9lFPuVx64v3fWDAQPbzMHuHuQZ/kN+lhF0DeF7zZGgtm2fcAICN4njBfqsFo5aKQ 6TBLnZLorH5BtvE4LNRi/aO71U9LZlxuHXciiwbf85Okc2O2t5xYqbkfxlRyPVRrTS4I 6gXGosY3ePrhf+2oC7dxp0vfX+Wv47V2o0Um7G+chZywow/YzL5vKcHT3w5kvJleYGVL wdbQ== X-Gm-Message-State: AC+VfDzs6l+o2T1PYpve1x5nBktYjq1aevfNf2C+tZvqeW9NL0E7QEka 3W6Jsd3sq/Kb4wlr5Z0tIaqHvfWSufzSwLckKS2NnA== X-Google-Smtp-Source: ACHHUZ4EGhgzHzZ0WQ2rZFOOmgebjbdOlQRJw7JO5X2SD5lqTyK17prLnh+nVXUOUJaXJfs+rGxKog== X-Received: by 2002:a5d:58d4:0:b0:309:40ba:1eb0 with SMTP id o20-20020a5d58d4000000b0030940ba1eb0mr9001854wrf.40.1684829305308; Tue, 23 May 2023 01:08:25 -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 n1-20020a05600c294100b003ee74c25f12sm14068162wmd.35.2023.05.23.01.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Spurious errors on class-wide preconditions of private types Date: Tue, 23 May 2023 10:08:24 +0200 Message-Id: <20230523080824.1873672-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 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, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Javier Miranda The compiler reports spurious errors processing the class-wide preconditions of a dispatching primitive of a private type T, when the class-wide precondition invokes another dispatching primitive of T that has the same name as a record component of T. gcc/ada/ * sem_prag.adb (Analyze_Pre_Post_Condition_In_Decl_Part): Remove call to preanalyze class-wide conditions since here it is too early; they must be preanalyzed when full views of private types have been analyzed. * sem_ch7.adb (Analyze_Package_Specification): Preanalyze class-wide conditions of dispatching primitives defined in nested packages. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch7.adb | 14 ++++++++++++++ gcc/ada/sem_prag.adb | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index 2610a7bba4d..aed09f30934 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1936,6 +1936,20 @@ package body Sem_Ch7 is end; end if; + -- Preanalyze class-wide conditions of dispatching primitives defined + -- in nested packages. For library packages, class-wide pre- and + -- postconditions are preanalyzed when the primitives are frozen + -- (see Merge_Class_Conditions); for nested packages, the end of the + -- package does not cause freezing (and hence they must be analyzed + -- now to ensure the correct visibility of referenced entities). + + if not Is_Compilation_Unit (Id) + and then Is_Dispatching_Operation (E) + and then Present (Contract (E)) + then + Preanalyze_Class_Conditions (E); + end if; + Next_Entity (E); end loop; diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 234b02d7b72..ca55a6f8290 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -26269,20 +26269,6 @@ package body Sem_Prag is Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); Set_Is_Analyzed_Pragma (N); - -- If the subprogram is frozen then its class-wide pre- and post- - -- conditions have been preanalyzed (see Merge_Class_Conditions); - -- otherwise they must be preanalyzed now to ensure the correct - -- visibility of their referenced entities. This scenario occurs - -- when the subprogram is defined in a nested package (since the - -- end of the package does not cause freezing). - - if Class_Present (N) - and then Is_Dispatching_Operation (Spec_Id) - and then not Is_Frozen (Spec_Id) - then - Preanalyze_Class_Conditions (Spec_Id); - end if; - Restore_Ghost_Region (Saved_GM, Saved_IGR); end Analyze_Pre_Post_Condition_In_Decl_Part;