From patchwork Tue Dec 6 14:02:11 2022 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: 61569 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 D3E583871FB9 for ; Tue, 6 Dec 2022 14:06:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3E583871FB9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335613; bh=/krFv1IUvcjS9giow8fjB6TLZL/zx4QxIUBOK+ZQ2ic=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mOJHCoUFI6ZWJeJx6VMdKQwsZLBYo1sTQrP42asAsnRxXo9j7iG/rQBwLlQmcQ3t2 L7e4GdZSm9I4hzgQdZ6iucLKABI74H1ctTEcECMQqug5R8dahaItGu0CLziNK0HfEw XIGvvMDK1OqcE9nWdacNSNHtN+WmhjKqJfappQ1g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 9D8413846982 for ; Tue, 6 Dec 2022 14:02:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D8413846982 Received: by mail-wm1-x32a.google.com with SMTP id ay40so4528247wmb.2 for ; Tue, 06 Dec 2022 06:02:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/krFv1IUvcjS9giow8fjB6TLZL/zx4QxIUBOK+ZQ2ic=; b=k5bfpkhGvz7wyEdhd3bbsIQp+Kf/b7mU/6Va30FewVvrrIqq9UZJ5qV/BLDEBHGzMr N3uGqzgnZ9oHT32EFa+V3hddJ37l63HV5iQF+6uh3OCNGqWnbDetgK7+Vc60GH9Z2Sl7 HhNeWOe4OPEXaxesGA2MedoXcf9YnoJjDw77dmQ0s7p/mreAQ9drTWWINpijtWW61Ylx 8dNYBNnVhpmd53YEJmnAnqWC+Bf28FmaRHv0Dxq7BM3QW+SNyL5XSNzbyRCQWp92RDri hWCwPUOzWVz7QMNhh/UgQv5HtUGPneaWH2n9D8QJ1dMygB4X+TU3Xb91AkoZLk2ngUNB qqtA== X-Gm-Message-State: ANoB5pnjjoNVfpz3ucyjCm2uQMzfmFcFCelljgt8gk6t4OWTnpyNeCrf blMoAAAOLOp8CLPdtFZoMeS+lDEqgDFf8ppx X-Google-Smtp-Source: AA0mqf5VbA/9zGKVEWjwIOFewr7UCA2ZvxnP0PiwQMwiPG1HZ5i34w7Ys6Au7xwa6lsLWIdFLeXUoA== X-Received: by 2002:a05:600c:1e8a:b0:3d1:cda5:bdc7 with SMTP id be10-20020a05600c1e8a00b003d1cda5bdc7mr6226468wmb.204.1670335334309; Tue, 06 Dec 2022 06:02:14 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id h130-20020a1c2188000000b003b4fdbb6319sm24707124wmh.21.2022.12.06.06.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:02:13 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix spurious error in checking of SPARK elaboration Date: Tue, 6 Dec 2022 15:02:11 +0100 Message-Id: <20221206140211.717323-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 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 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou The problem is that the computation of early call regions skips freeze nodes but scenarios involving procedures declared as actions of these freeze nodes are taken into account. As a consequence if a subprogram body, typically of an expression function, is placed just after a freeze node, its early call region depends on whether the construct just before the freeze node can be preelaborated or not; in other words, the legality of calls made from the actions of this freeze node to the subprogram depends on what happens ahead of the freeze node, which may be totally unrelated to the situation. This change disables the ABE diagnostics in this case, as is done in a few other similar cases leading to bogus errors too. gcc/ada/ * sem_elab.adb (Processing_In_State): Add Within_Freezing_Actions component. (Process_Conditional_ABE_Call): Compute its value. (Process_Conditional_ABE_Call_SPARK): For a call and a target in the main unit, do not emit any ABE diagnostics if the call occurs in a freezing actions context. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_elab.adb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb index a1e8f1ef30b..9bf8614fd52 100644 --- a/gcc/ada/sem_elab.adb +++ b/gcc/ada/sem_elab.adb @@ -881,6 +881,10 @@ package body Sem_Elab is -- The subprogram body traversal mode. Once set, this value should not -- be changed. + Within_Freezing_Actions : Boolean := False; + -- This flag is set when the Processing phase is currently examining a + -- scenario which was reached from the actions of a freeze node. + Within_Generic : Boolean := False; -- This flag is set when the Processing phase is currently within a -- generic unit. @@ -5353,6 +5357,7 @@ package body Sem_Elab is Subp_Id : constant Entity_Id := Target (Call_Rep); Subp_Rep : constant Target_Rep_Id := Target_Representation_Of (Subp_Id, In_State); + Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); Subp_Decl : constant Node_Id := Spec_Declaration (Subp_Rep); SPARK_Rules_On : constant Boolean := @@ -5452,6 +5457,16 @@ package body Sem_Elab is or else not Elaboration_Warnings_OK (Call_Rep) or else not Elaboration_Warnings_OK (Subp_Rep); + -- The call occurs in freezing actions context when a prior scenario + -- is already in that mode, or when the target is a subprogram whose + -- body has been generated as a freezing action. Update the state of + -- the Processing phase to reflect this. + + New_In_State.Within_Freezing_Actions := + New_In_State.Within_Freezing_Actions + or else (Present (Body_Decl) + and then Nkind (Parent (Body_Decl)) = N_Freeze_Entity); + -- The call occurs in an initial condition context when a prior -- scenario is already in that mode, or when the target is an -- Initial_Condition procedure. Update the state of the Processing @@ -5502,7 +5517,7 @@ package body Sem_Elab is In_State => New_In_State); Traverse_Conditional_ABE_Body - (N => Body_Declaration (Subp_Rep), + (N => Body_Decl, In_State => New_In_State); end Process_Conditional_ABE_Call; @@ -5721,6 +5736,13 @@ package body Sem_Elab is if In_State.Suppress_Warnings then null; + -- Do not emit any ABE diagnostics when the call occurs in a + -- freezing actions context because this leads to incorrect + -- diagnostics. + + elsif In_State.Within_Freezing_Actions then + null; + -- Do not emit any ABE diagnostics when the call occurs in an -- initial condition context because this leads to incorrect -- diagnostics.