From patchwork Thu Jun 13 13:33:18 2024 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: 1947413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=OPCHvpUc; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0NnW5xt4z1ydW for ; Thu, 13 Jun 2024 23:39:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07D603882AE5 for ; Thu, 13 Jun 2024 13:39:58 +0000 (GMT) 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 A1CFB388216A for ; Thu, 13 Jun 2024 13:34:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1CFB388216A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1CFB388216A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285642; cv=none; b=o0ytw7HefJ7iCipqmv2NjUpD5dcndfVfhQGuuVYKtxEo/NA9pibkbjGPvadR1d3Pie2qmh5hxsALFSN03gTs7eZonuMXl6/b9anZAwnGQYLWmw1QiDRkY65jTelz5WbFNg0tezMQ4IjA40CjQR6YZqG0YPTTSPHRkHscgBUo0zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285642; c=relaxed/simple; bh=+f2xxKs6jG6calEhJWujbvvShOHY02yN2VBlIy9Ib8A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p0bV0uXS8bY5spx+pD1X4FTMnCBLAbCjjUOlaA223GMVfjz2i6uJkZ29sy3fHFBFwRn5sim78OHIoEJAD9hB0dYnq1en+Jjw9dXETm13o5fuZRha3zTMlbJPyQAm4UEdhPUP9jf8BRVevZm1aen0GG6simAWZh+wbfu1uWy25dM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so6587265e9.1 for ; Thu, 13 Jun 2024 06:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718285639; x=1718890439; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fDWCsAI7H81E1tI5XMeJB7Gm4omL/oGikXkpDuKsr2A=; b=OPCHvpUcY7hSbgyCPqIaZE3dFXUJ1Q/0BATmst2+boQlnIjNqdgA6hApMNpWJqlik8 XinmEYoNqdlwOT6B/haikNAUZhuJ2zAG0svpk/YYgvq9Xx4AH4WDQtOd12bDcQUIHmMY Y/8f53vBqJozUfKPIZCDXmc9YKBJAACFvcSY0tHOlM5afSgzWyJt5Ww849wNXYtd1LQH hJWvcGp/540AUdTXjy+1wsG+IeWNbVN1WeCf4teLjrjQ+t4onoUw8vNT43mkV0n25Sed IxoOtQk/PtwIyEoPgV/B96ndwdtPdTGVb7gBnC2fEMYEBaMJIbiK5HCBiKRcED7X/N2W XcRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285639; x=1718890439; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fDWCsAI7H81E1tI5XMeJB7Gm4omL/oGikXkpDuKsr2A=; b=a63Vj2R6EjqdPQbZAWyT5J4nJKrNVfFMVQEYdx0s+4KEt1XX0NfE5O1s33ZMui9mOg MWuBbKn++/L4h46SCf3TfcfQF0Jfdgbpi3T9sBUD6GGuifS+gu36J4OKryLwjl7Kwtu1 3UYpN13BgnM5jWp5M2gkJIsexIXjbUOrKwUGNWtO3PR5yK5YC8jOIU5zuVQYp0v6ZJcN 2Ht/NS/d1JpPhnWFxUN/2ReWdYXQDk3q1sDATdVrd7TjBHHv6ypAolgO945/RDEX00KQ Y6fmp48AIRjUe7xCjJUF28zd212wP3HjIeANezwivNm+Hvs8x69WeUtNm6/5UB7OpYr3 k0EA== X-Gm-Message-State: AOJu0Yz2hlfzsM0xp8SfJh0QtZT+1rtWXhVUDwiSIBsXS8cRH8Gw7hdy XEKAI/Um8jQGbXfST/LRX+sZKFJsh8whVPSyUhLRfZ+5QceX3zs/9kOdyOqdxe2oUE6Va0IckUA = X-Google-Smtp-Source: AGHT+IHOXKW03CQF0rwNUF+49dCaLEOEYIY1kYDRmA514R+hMSMAdCzrnNnWDK+Y0NBmoFlYl3Mhyg== X-Received: by 2002:a05:600c:1c9c:b0:418:2981:c70f with SMTP id 5b1f17b1804b1-422b89b1458mr27314625e9.19.1718285639421; Thu, 13 Jun 2024 06:33:59 -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 5b1f17b1804b1-422870e9145sm62391955e9.22.2024.06.13.06.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:33:58 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 12/30] ada: Check global mode restriction on encapsulating abstract states Date: Thu, 13 Jun 2024 15:33:18 +0200 Message-ID: <20240613133338.1809385-12-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240613133338.1809385-1-poulhies@adacore.com> References: <20240613133338.1809385-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Piotr Trojanek We already checked that a global item of mode Output is not an Input of the enclosing subprograms. With this change we also check that if this global item is a constituent, then none of its encapsulating abstract states is an Input of the enclosing subprograms. gcc/ada/ * sem_prag.adb (Check_Mode_Restriction_In_Enclosing_Context): Iterate over encapsulating abstract states. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_prag.adb | 81 ++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 6d4ec122a21..d3b29089d77 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -2966,16 +2966,18 @@ package body Sem_Prag is (Item : Node_Id; Item_Id : Entity_Id) is - Context : Entity_Id; - Dummy : Boolean; - Inputs : Elist_Id := No_Elist; - Outputs : Elist_Id := No_Elist; + Context : Entity_Id; + Dummy : Boolean; + Item_View : Entity_Id; + Inputs : Elist_Id := No_Elist; + Outputs : Elist_Id := No_Elist; begin -- Traverse the scope stack looking for enclosing subprograms or -- tasks subject to pragma [Refined_]Global. Context := Scope (Subp_Id); + Check_Context : while Present (Context) and then Context /= Standard_Standard loop -- For a single task type, retrieve the corresponding object to @@ -2997,35 +2999,64 @@ package body Sem_Prag is Subp_Outputs => Outputs, Global_Seen => Dummy); - -- The item is classified as In_Out or Output but appears as - -- an Input or a formal parameter of mode IN in an enclosing - -- subprogram or task unit (SPARK RM 6.1.4(13)). + -- If the item is a constituent, we must check not just the + -- item itself, but also its encapsulating abstract states. - if Appears_In (Inputs, Item_Id) - and then not Appears_In (Outputs, Item_Id) - then - SPARK_Msg_NE - ("global item & cannot have mode In_Out or Output", - Item, Item_Id); + Item_View := Item_Id; - if Is_Subprogram_Or_Entry (Context) then - SPARK_Msg_NE - (Fix_Msg (Subp_Id, "\item already appears as input " - & "of subprogram &"), Item, Context); - else - SPARK_Msg_NE - (Fix_Msg (Subp_Id, "\item already appears as input " - & "of task &"), Item, Context); + Check_View : loop + -- The item is classified as In_Out or Output but appears + -- as an Input or a formal parameter of mode IN in + -- an enclosing subprogram or task unit (SPARK RM + -- 6.1.4(13)). + + if Appears_In (Inputs, Item_View) + and then not Appears_In (Outputs, Item_View) + then + if Item_View = Item_Id then + SPARK_Msg_NE + ("global item & " & + "cannot have mode In_Out or Output", + Item, Item_Id); + else + Error_Msg_Node_2 := Item_View; + SPARK_Msg_NE + ("global constituent & of & " & + "cannot have mode In_Out or Output", + Item, Item_Id); + end if; + + if Is_Subprogram_Or_Entry (Context) then + SPARK_Msg_NE + (Fix_Msg (Subp_Id, "\item already appears " + & "as input of subprogram &"), Item, Context); + else + SPARK_Msg_NE + (Fix_Msg (Subp_Id, "\item already appears " + & "as input of task &"), Item, Context); + end if; + + -- Stop the traversal once an error has been detected + + exit Check_Context; end if; - -- Stop the traversal once an error has been detected + if Ekind (Item_View) in E_Abstract_State + | E_Constant + | E_Variable + then + Item_View := Encapsulating_State (Item_View); + + exit Check_View when No (Item_View); + else + exit Check_View; + end if; + end loop Check_View; - exit; - end if; end if; Context := Scope (Context); - end loop; + end loop Check_Context; end Check_Mode_Restriction_In_Enclosing_Context; ----------------------------------------