From patchwork Tue Jan 7 12:53:25 2025 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: 104248 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 B4BBF3861029 for ; Tue, 7 Jan 2025 13:11:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 91C1B385626B for ; Tue, 7 Jan 2025 12:54:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91C1B385626B 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 91C1B385626B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736254454; cv=none; b=lonOKZi8Ng7XQdXlDz72Ey2rLDGLPZnls4ABcJYy7+G+ddK5qB36Wo0bn49rQ9YYtaD6ZUNVLThR0OaDNKRSLJ+Fs3KNhMRJ4++2KYyuRbDH2l/scoHy9utnEqshOzuAymCiMgK+Om5Strjvt05M8OByuGOTul3XRWK8ftKy8V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736254454; c=relaxed/simple; bh=aJ4Zwj3yMf4iSnHP+NSRtZNgHSSl7aR8kxkH4CT5ogU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZrxfxhXd/Ju9JyUlkMkwP1sm6MQlqyyK22hVsjk6oWgWlr00q/mr+9xueJMxatbN1F8JiMwH3j/Z04IbxNeFg9z7nC5X4qxspQwTA6ttNfvyQXMAZVa6KBTFbFWBp6YQAcsc+hPtjYYWsBtejyNHHA8v7/2RoWOuWLkBhfPF6Zc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91C1B385626B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=SjvP0UBQ Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4362f61757fso153861305e9.2 for ; Tue, 07 Jan 2025 04:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1736254453; x=1736859253; 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=uirUWXiFGx9XTJuwWh/f2C8Z+OOmdBPmO2kl/jVa+XE=; b=SjvP0UBQ+wH/IWS5K7xg9U0Je79c/R2HjZnnchipoNitjE8dBUc0f076fuvaw2gJia f2wNTl8D3wiT2LT8712Kyn/BF5Ss80ph2LyyUQYnwPBnD2Dz0khuGlAOSAmqskR8daDF fWUxsaVxlBj0NHgg46oCGva3njCW8YmX+Kajf1WcZKY00di0TeuKppCM5+aXeQXhong3 6/nRvEGTz4LTWhU3coO/JqL3RhIxpVKwgWaKEbL4aHBRDNUO0CURLUaFTjxQLY/BwF47 LcM0D0ZCp0r4EjFQKrCESSwrqkDPVNwgGeaECCObNyL2/2cNZsaufCVrDGL/NGpEsfYM p2Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736254453; x=1736859253; 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=uirUWXiFGx9XTJuwWh/f2C8Z+OOmdBPmO2kl/jVa+XE=; b=bx+EXjfhpvGdXZzUvzsKDaz8pZzu8aeymqMYpgNseqNKjQ669qDAV8+1ISrlQ/YiXV 0qOVaj2a5mtDIaTGs711Jq08kmy7/iAEV2prz9PcLCmozeXhBVj5XNM9OJST5p2UnXE3 JDxXwup9A76DRKDu5IZL5HvuMkKp84snZ9DnDi2Uy9QsBG7EeSsIRPEIuF39tjt8eSm6 5L+fAA5CHrvhrx/6aZYUEiSgnIQh5L5Dfoz83a3Zt6SUtl6J6tmQSzmgYcNWSdF0XexD 1m+Osvw9hYJWFIkIuwBB79MkjIsd3rsApYXHeMms/urC5HNhlIAYWtnqe9O+/308NSOw oFgQ== X-Gm-Message-State: AOJu0YwrUX6OJ8x8j1bPxNk6+EFgGBjuB6qlRxYccazw7l3VFXCOpcpj 05vGu2tC5BpCLJmFUrisZlJyElTig1mqEEa7Tgl7ipURpo8PWjGfe43XkunfP8mheI3LgAd1nW4 = X-Gm-Gg: ASbGncu8yFRN1m4gvc3hOMJqdmjSX8OA5zj4lZzLYaZLE+yEivv+ymK3+fmTEyhvHYK lo6UTUI2KJUAOYZWifWmSwxTAt1VKDU96tQtEzj19LnM99talBAObfPpjej79xIFlvVJbB8i2tb /xsx888mGpZfi0ar2A1VS/44AnbodVnS0Ss6IIGZwN+MwekydZypiFFBulmCarPuOHRqYxCHcTJ 843XT0WeKq+P6z25c1nOMcFAYqa71j2/tpMAdKkkyb1FbEUN3X9O9RptrLsibryPqY08n77FDux wKRIFNwIZwhSDrXfJFLU3WsRCqZpzlgVRADwGcUBsSUNQ4QA2bxPJitMuRn/fdvnHCpzC2l+ X-Google-Smtp-Source: AGHT+IE+9FiiyubLSJgbYKXWY0ScytE9kAgTl2AFV5M181ns1Lh7Lewpzq09wp3uY/8HKpPwWSjoLw== X-Received: by 2002:a05:600c:1d2a:b0:435:330d:de86 with SMTP id 5b1f17b1804b1-4366790d3c0mr583556295e9.0.1736254453150; Tue, 07 Jan 2025 04:54:13 -0800 (PST) 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-43656af6c42sm631014805e9.9.2025.01.07.04.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 04:54:11 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 07/31] ada: Move checks for consequences of Exceptional_Cases to GNAT Date: Tue, 7 Jan 2025 13:53:25 +0100 Message-ID: <20250107125350.619654-7-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250107125350.619654-1-poulhies@adacore.com> References: <20250107125350.619654-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 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~patchwork=sourceware.org@gcc.gnu.org From: Piotr Trojanek Previously checks for consequence expressions of Exceptional_Cases aspects were done in GNATprove backend. However, we can do them in the frontend, where they will apply to all subprograms, regardless of the SPARK_Mode aspect. gcc/ada/ChangeLog: * sem_prag.adb (Analyze_Exceptional_Cases_In_Decl_Part): Move check from GNATprove backend to GNAT frontend. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_prag.adb | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 04202873974..b7de1cd8afa 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -2211,6 +2211,72 @@ package body Sem_Prag is procedure Check_Duplication (Id : Node_Id; Contracts : List_Id); -- Iterate through the identifiers in each contract to find duplicates + function Check_Param (N : Node_Id) return Traverse_Result; + -- Parameters of modes OUT or IN OUT of the subprogram shall not occur + -- in the consequences of an exceptional contract unless they are either + -- passed by reference or occur in the prefix of a reference to the 'Old + -- attribute or as direct prefixes of attributes that do not actually + -- read data from the object (SPARK RM 6.1.9(1)). + + ----------------- + -- Check_Param -- + ----------------- + + function Check_Param (N : Node_Id) return Traverse_Result is + begin + case Nkind (N) is + when N_Identifier | N_Expanded_Name => + declare + Id : constant Entity_Id := Entity (N); + begin + if Present (Id) + and then Ekind (Id) in E_Out_Parameter + | E_In_Out_Parameter + and then Scope (Id) = Spec_Id + and then not Is_By_Reference_Type (Etype (Id)) + and then not Is_Aliased (Id) + then + declare + Mode : constant String := + (if Ekind (Id) = E_Out_Parameter then "out" + else "in out"); + begin + Error_Msg_N + ("formal parameter of mode """ & Mode + & """ in consequence of Exceptional_Cases", N); + Error_Msg_N + ("\only parameters passed by reference are allowed", + N); + end; + end if; + end; + + when N_Attribute_Reference => + case Attribute_Name (N) is + when Name_Old => + return Skip; + when Name_Constrained + | Name_First + | Name_Last + | Name_Length + | Name_Range + => + if Nkind (Prefix (N)) in N_Identifier + | N_Expanded_Name + then + return Skip; + end if; + when others => null; + end case; + + when others => null; + end case; + + return OK; + end Check_Param; + + procedure Check_Params is new Traverse_More_Proc (Check_Param); + ---------------------------------- -- Analyze_Exceptional_Contract -- ---------------------------------- @@ -2324,6 +2390,8 @@ package body Sem_Prag is Preanalyze_Assert_Expression (Consequence, Any_Boolean); + Check_Params (Consequence); + -- Emit a clarification message when the consequence contains at -- least one undefined reference, possibly due to contract freezing.