From patchwork Mon May 15 09:44:25 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: 94067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6796256vqo; Mon, 15 May 2023 02:59:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MNLWUDaIfA9QFfq6xaZ75RzsDi4YX2mVUMP+SizOIV0+3WnU4q8RhzRcIv0iaO8YZfuaY X-Received: by 2002:aa7:c7d0:0:b0:504:9346:11d3 with SMTP id o16-20020aa7c7d0000000b00504934611d3mr27873242eds.29.1684144755113; Mon, 15 May 2023 02:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684144755; cv=none; d=google.com; s=arc-20160816; b=k5QsoEYFCOc5/Nh0QvZb1xxA2a5lNxqryOtNKtC/KQECEooZvL4lNlGmE86e8u6si+ 3DiN0uVLauK/RQ7Fw/FtxwefiNXKbs7cvJNJYS7H+CHBTwlbd0mwflxgiDYNmTnvQz1S 2T7bk7uFIsR94SiaPhGmc3asMxJfBkSmsMouQdf0d0o17ibZHGI2lFjRobuergq1ga4J Jyql5zX2Eoeb3vG3Xv8IcVS5t/AuEvZFBNL/dDtInMiANI/4lFrnJjWPyrvbzXGXY7Py zPA7De+F1ne8PEfrKbdGi6DQMUO0SNQnizZQWTdag1RV+qTN0AEXigMD+4BbLpFq/VpA vNlg== 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=foPzw+N2AV5uo9t+VKZPAmB2q4E7HR0xBzqyDIMv3Lg=; b=ad6KGJwEu8PVVGpCa07mBuOkbFUSOyAR8oPtxAcabeEZTrDHWqOLuybblmJEOSJJqu XrlCYaPwnKNnK7eZtQkXDlbeyn9gBkTUJXMsgBjEKgRP8jjCnbGMvPUui7S4TrpyaFp1 bKcPA/rsfSub9B5ypbckZBW4ymjo/6tnom74eI8d03R/Yo+0J8Jm9JYVsy2m48+UHcMm QFDKRPZVzVopQDfNCxiRjRO7N9wrBePDIheoqbMPaaPmDHiDmh50UFqyoOAiay59hZU0 kG+yH5/qNSYHINOv7xnMZKUlgSehDlTEz/j6hoA1oc7da6HbRkuINjHsM8/g71/zjtz1 a2nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EdgyrZee; 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 ay7-20020a056402202700b0050bfc4d942dsi12312140edb.637.2023.05.15.02.59.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:59:15 -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=EdgyrZee; 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 586693882671 for ; Mon, 15 May 2023 09:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 586693882671 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684144382; bh=foPzw+N2AV5uo9t+VKZPAmB2q4E7HR0xBzqyDIMv3Lg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=EdgyrZeeONTh3Dupo+fmFNb7DqSZDhbiCivYcslEJ4nUwHjPgnc1BMpQ4g8A+NZwX 6Y5sShXqm4tFxjP/JBIwnJrhlLhFisgvhtk74C4uefGj7PWETUrnJGtOmtNlS8pzoM jtDiWJ0MKtW6hlpkB8L0i+Ozw2urFuSDhia/IoXc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 4D4983836F0F for ; Mon, 15 May 2023 09:44:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D4983836F0F Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f435658d23so62432255e9.3 for ; Mon, 15 May 2023 02:44:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143868; x=1686735868; 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=foPzw+N2AV5uo9t+VKZPAmB2q4E7HR0xBzqyDIMv3Lg=; b=I9NUFYo7O7q+TxLmH8VDEhBUkMTqW19sCSaGpFbZMK7ICOBO01DyD1z35wXg7mPExD mb7EfZhDXvZ5+r0e55Ac3SYPrvE8Ps8OUQVjKp9GzR9ZQfCJmdJBHy9ITP1NsBO2p59f LBoBjZRScDUYspUIsl4qXvVbFxGDHq4yMuMK+BIyvK83PKsoPh5K3lSJRxq0SnYCXVci qzYHUi/yZyjzRsB50XDT00Q0fdkk2pjYSR8mOw4V71xhm1gRkKWRrBwi28pvGV+9+1O2 jSr+e65SHuKwETx7jbmoH08+KWTvamvtCMPFu6VffhMNIP0bDc7nrQGuL8BcYDOnMjEf JyrQ== X-Gm-Message-State: AC+VfDwZtLQPzfE9Yc6v9d0l3t2ExCPkwDcJG9OYuDRZpS45v5PA5O3A CL9413kn97dftgSfNOWmeVoD3OgETAloKqhBMitWPw== X-Received: by 2002:a05:600c:2207:b0:3f5:6e5:1689 with SMTP id z7-20020a05600c220700b003f506e51689mr2838276wml.17.1684143867835; Mon, 15 May 2023 02:44:27 -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 c3-20020a7bc843000000b003f42314832fsm24531047wml.18.2023.05.15.02.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:44:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [COMMITTED] ada: Recover proof of Interfaces.C for termination Date: Mon, 15 May 2023 11:44:25 +0200 Message-Id: <20230515094425.1408943-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 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?1765953770753574003?= X-GMAIL-MSGID: =?utf-8?q?1765953770753574003?= From: Yannick Moy GNATprove reports possible non-terminating loops in functions marked as terminating. Add loop variants to prove loop termination. gcc/ada/ * libgnat/i-c.adb: Add loop variants. Remove useless initialization. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/i-c.adb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/ada/libgnat/i-c.adb b/gcc/ada/libgnat/i-c.adb index 4cfccf41b1c..9236189fc15 100644 --- a/gcc/ada/libgnat/i-c.adb +++ b/gcc/ada/libgnat/i-c.adb @@ -186,7 +186,7 @@ is (Item : char_array; Trim_Nul : Boolean := True) return String is - Count : Natural := 0; + Count : Natural; From : size_t; begin @@ -200,6 +200,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -257,6 +258,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -333,6 +335,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= wide_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -390,6 +393,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= wide_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -466,6 +470,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= char16_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -523,6 +528,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= char16_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -599,6 +605,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= char32_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error; @@ -656,6 +663,7 @@ is pragma Loop_Invariant (for all J in Item'First .. From when J /= From => Item (J) /= char32_nul); + pragma Loop_Variant (Increases => From); if From > Item'Last then raise Terminator_Error;