From patchwork Thu Jun 15 08:04:10 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: 108319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp467965vqr; Thu, 15 Jun 2023 01:08:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LBmdW2JeQ5oOFWbY02a8FS0Y81yc+K7ePIP6RUtgJd6+iTyoyH6FQR99FEGi9lmZ2l1Ey X-Received: by 2002:a17:907:7e9a:b0:94f:3521:394 with SMTP id qb26-20020a1709077e9a00b0094f35210394mr17768885ejc.51.1686816538122; Thu, 15 Jun 2023 01:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686816538; cv=none; d=google.com; s=arc-20160816; b=LWOD7jfCWo/2mdCwF0jwDH0R3WQXUshLDJyuLCcHg3Qh1aNHwvLcO4qo3PcRmRiMT3 vezbbsCAa7RHXTtYBdnHEvBl/NI8xY82EuG2UGfwaVOLmuAPZ8MHdmX6Sryna3FIHhzH UBOJqLFcPy+0lc1ZnN3vcEy9Dbgb/msni76aIMWnpPCxm7vvj0FHNyWU0KxhiXeos4O5 kw3E4/q1tBT2hkX2uqxfrPIzXtfqR/IuFGZbCKMyWFBYWu49xsnrmDV8lW/LtHaCk0su gEL8S9csAPVQ1uvwZLgxi/hWx38rqHW30K9Ba3b3tbRJq0sHsmsP+ZO4cyJmulN/fbHt Vpcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5Q+DSqFw/BR88FYDBTroJ5HmMBXZKVEzVqfPke3bsiQ=; b=QC9+aWP1vTMZk8EpE0YF3AyLLguQwGPiSu1jyZm2QHERSiN3qPzIembcs4ei35AgaG o3itbQNw5a/fVI2F2UQXgivK+fhMU4uUtmRpG/C/ZseVUYbwoMH0eNfBIk3s4XfQONid irFwvE0Ygz0jH3oS8OnW9ZmfNbHvw9ICEfAzPcubCSEjFi9UOOzhxi3nkZO3+Yx0YLU1 2MkgTC6i9vhZa41Ja40u8XDUqwaWAi0KR5usUwtpWbskrSL3JLnjoCPq3uy90aYQAK6I hyC3tOiF0sGZKoRWKb9CoeK1VY50d8RtCCUGUfhRCS5Sixi4PN60kDD3mrNfcMriTitr epvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UlCRjgh4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sa10-20020a170906edaa00b009829dc3fa8csi706716ejb.1052.2023.06.15.01.08.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:08:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UlCRjgh4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 500EA3882048 for ; Thu, 15 Jun 2023 08:06:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 500EA3882048 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686816381; bh=5Q+DSqFw/BR88FYDBTroJ5HmMBXZKVEzVqfPke3bsiQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UlCRjgh46OjGqewPlu0s/2kKT88xFb/ZK7v9t4yqQUVdjigUWuTkMCMacipBBkm1y 24alVA4GpYmOb0UIDj7kVObPjj4bdqe65a6+umLDBmeIt8QuNy0KS8fotEkAl7Vm/c 4m9gbBqJKWvdb0e8pHc6jBNZ2ii+FfzmT6qF6g3w= 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 BA9A13857835 for ; Thu, 15 Jun 2023 08:04:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA9A13857835 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f8cc042ea9so14009145e9.2 for ; Thu, 15 Jun 2023 01:04:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686816251; x=1689408251; 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=5Q+DSqFw/BR88FYDBTroJ5HmMBXZKVEzVqfPke3bsiQ=; b=HJqGxzHuvnrImvb8Sn0y5+ayMuGW5yTUK+/wpxjdiDJ2plNS4KNqEprwNfqKBoGPDl TbDqKHGJFpDOpe9JwseLBgmqPZYGEIy7uVngPPuEdkvwwKZqO7OSm6f5DOEHl/H8zP/A bOlV9b37P+L4npVVQh9E79Q9TVlj/ZnF9tvrM7l1x7jg1ryX0hvno+gphBq7iuzZ86y3 vutqwza4Tnf6Vtg1g8PPD2VlW5FWmlwxzqXljz39j67gB/6VtlbPXSy0N60yv4U8QThq zOT8Vh5gHbq5Mf85Vov8rgbg0oAb6FlX6ASWzuyCMg+Svv1ZliTBOjJQRcnE7/dOCCJJ Op+w== X-Gm-Message-State: AC+VfDyfCs8GMAQXNcGj/D5bI8+7kI4Zx32d9ZJiwAo2d//9nJ9Dd4dt kxmDGdrwogfrRcx5zsNonKRJrhRGySxCkMUqYKHjTQ== X-Received: by 2002:adf:f44d:0:b0:30f:cb5e:6b1b with SMTP id f13-20020adff44d000000b0030fcb5e6b1bmr5308327wrp.11.1686816251546; Thu, 15 Jun 2023 01:04:11 -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 h17-20020a5d4311000000b003048477729asm20228003wrq.81.2023.06.15.01.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:04:10 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Accept aspect Always_Terminates on packages Date: Thu, 15 Jun 2023 10:04:10 +0200 Message-Id: <20230615080410.939483-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 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.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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768755338046375877?= X-GMAIL-MSGID: =?utf-8?q?1768755338046375877?= From: Piotr Trojanek The recently added aspect Always_Terminates is now allowed on packages and generic packages, but only when it has no arguments. The intuitive meaning is that all subprograms declared in such a package are always terminating. gcc/ada/ * contracts.adb (Add_Contract_Item): Add pragma Always_Terminates to package contract. * sem_prag.adb (Analyze_Pragma): Accept pragma Always_Terminates on packages and generic packages, but only when it has no arguments. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/contracts.adb | 3 +++ gcc/ada/sem_prag.adb | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 0e87cee3ef5..26bc4b39735 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -296,6 +296,9 @@ package body Contracts is elsif Prag_Nam = Name_Part_Of and then Is_Generic_Instance (Id) then Add_Classification; + elsif Prag_Nam = Name_Always_Terminates then + Add_Contract_Test_Case; + -- The pragma is not a proper contract item else diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index b1e4439b9f2..bcae43ff59d 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -13332,9 +13332,14 @@ package body Sem_Prag is Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True); - -- Generic subprogram + -- Generic subprogram and package declaration - if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then + if Nkind (Subp_Decl) in N_Generic_Declaration then + null; + + -- Package declaration + + elsif Nkind (Subp_Decl) = N_Package_Declaration then null; -- Body acts as spec @@ -13394,6 +13399,17 @@ package body Sem_Prag is return; end if; + -- Pragma Always_Terminates applied to packages doesn't allow any + -- expression. + + if Is_Package_Or_Generic_Package (Spec_Id) + and then Arg_Count /= 0 + then + Error_Msg_N (Fix_Error + ("pragma % applied to package cannot have arguments"), N); + return; + end if; + -- A pragma that applies to a Ghost entity becomes Ghost for the -- purposes of legality checks and removal of ignored Ghost code.