From patchwork Fri Sep 2 07:53:26 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: 921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp611574wro; Fri, 2 Sep 2022 00:58:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vuIHff3fV8kMVSTWkH1ZZd16bqLYclL9ScMx9amtLjlEk32bkvRyATgPK2EjycQwz+TMQ X-Received: by 2002:a17:906:8472:b0:741:5bf7:916d with SMTP id hx18-20020a170906847200b007415bf7916dmr17925495ejc.57.1662105493079; Fri, 02 Sep 2022 00:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662105493; cv=none; d=google.com; s=arc-20160816; b=e2cByC1ycM2M0vJwDk1pUglrrnECI/w+b7K/P7y7a0uYgZMecO53sQPXkzq/C3E4Mj J6AwkVsQmwMmlrf9SNnJ2u4wZnBZiZ9R/vNctIPIfLMxjk8PBdu6iTROzSRkHDOXnjAB yWHGM612jm4XMly34Za4g0bR6NA6baJ6IZEKtjoFn83pIdzAbiK8lOXyF1B/prcn3a54 nKrm16d531zIVYckOSFeBz4maDUHNPWxOrYcYaBs/Kx5ZJwepA71BU9RkIHFPbW4aVkb zJwsteeZehu+ftMW6TEwYwWuNN16b7JqDnrv1lxxdpukn0JbASI56SW4HwYUTVgyK+pY GynA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oWt1oUwUFQHscE5begJ6W8QGsx8+y4g9joFUY+xR8so=; b=flYB5o113mXBV2UFmUzN29ktvK6M1igWDZpqnchL7QQ/61SCrnbLEtuO9Xp7JoDJ/b X0WTjskMACp57B1hdbZX2GfxRNMhNfhT6n4qWyyTXrcQKHb0I9z3d0MdL+Uc9sXK8kk2 avYFs8LOCa2oLE7ftZcnUGRd/4XDl7abhzelPgODVzYb4If5aM24dTarE+VNkqd0B8XI MJgn3aJkLyrUleTXlIEc5RotawPGNtzhYDt9uLNWXHQzR9uum0Gohe/8+KvfbxeCKhAg cZf/47dLTgKXKZVK+N/VIuslrv04ZOfGTPHegu76WhvegZBK4vrXpUTTyGF0Y4/xaJzN bkFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ccp+EAsh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id ht16-20020a170907609000b0073bebc45090si1453375ejc.392.2022.09.02.00.58.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 00:58:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ccp+EAsh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 54E853857428 for ; Fri, 2 Sep 2022 07:56:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54E853857428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662105385; bh=oWt1oUwUFQHscE5begJ6W8QGsx8+y4g9joFUY+xR8so=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ccp+EAshZrB6/loUb810O2hYzeAx5WAi4yEespKeDzvaX001HGeMWbrwK3ervZi+u C5tjp2i3dq4Km/dUihtE5+2yOWmOEjGDu29DCgcrIf9eME+J5SoyJ2+gDOVHcyodMz pScksLde/Z2O9orzfHH/ArBroIiltgXXYQrRCk7c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 517E3385829C for ; Fri, 2 Sep 2022 07:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 517E3385829C Received: by mail-wr1-x42c.google.com with SMTP id az27so1230779wrb.6 for ; Fri, 02 Sep 2022 00:53:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=oWt1oUwUFQHscE5begJ6W8QGsx8+y4g9joFUY+xR8so=; b=pC/Mf44uSfk3/dNzUbGihdoVCSbSwykJzEyj5ffZsf8agGQqfTO/1Wa3JUlIpQb1Qj OT2BZgcR0RzW+RK0pNiDL9s+cquIVdT5Ctk1Pv/SqqCMco7ESieuwepFyx5tmC5VK0FD AKIhWafMcLBbH0Xf9QQ8qb1rLYXw55DNY856wIJs8FpVlN0uxPcU2wXsTLnC57mZ98I8 gmfHRB4fgU8dOKyOeCw81snHC7EfKlDI45QdJaUgQrNIhxhhvboHfcbZzM/kY8ZlNDPT 5n+ynj3KYaovbyd4ur3/oWgQE2eKYDa0Nk9aAcAkXUL0wTEZAPgETNSvWnwZpEyi5juY tREg== X-Gm-Message-State: ACgBeo2hQYO9ywoRwnKt8wzwu3QqDTAIzXlWTrHRi45mMmrVdJB/b0nd ugOplXfoli9hLMSVjICOrMt3EgrDzo32qg== X-Received: by 2002:a05:6000:168c:b0:226:f4c2:d6db with SMTP id y12-20020a056000168c00b00226f4c2d6dbmr3942609wrd.659.1662105208128; Fri, 02 Sep 2022 00:53:28 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id i11-20020a5d522b000000b00226d473ebd6sm840589wra.86.2022.09.02.00.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 00:53:27 -0700 (PDT) Date: Fri, 2 Sep 2022 09:53:26 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Add loop variants to Ada.Strings.Search and Ada.Strings.Maps Message-ID: <20220902075326.GA1121061@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.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, 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: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Claire Dross 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?1742843929816536894?= X-GMAIL-MSGID: =?utf-8?q?1742843929816536894?= Add loop variants to verify that loops terminate in string handling. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/a-strmap.adb: Add variants to simple and while loops. * libgnat/a-strsea.adb: Idem. diff --git a/gcc/ada/libgnat/a-strmap.adb b/gcc/ada/libgnat/a-strmap.adb --- a/gcc/ada/libgnat/a-strmap.adb +++ b/gcc/ada/libgnat/a-strmap.adb @@ -290,6 +290,7 @@ is loop pragma Loop_Invariant (Seq1 (Seq1'First .. J) = Seq2 (Seq2'First .. J)); + pragma Loop_Variant (Increases => J); if J = Positive'Last then return; @@ -440,6 +441,7 @@ is (Character'Pos (C) >= Character'Pos (C'Loop_Entry)); pragma Loop_Invariant (for all Char in C'Loop_Entry .. C => not Set (Char)); + pragma Loop_Variant (Increases => C); exit when C = Character'Last; C := Character'Succ (C); end loop; @@ -457,6 +459,7 @@ is pragma Loop_Invariant (for all Char in C'Loop_Entry .. C => (if Char /= C then Set (Char))); + pragma Loop_Variant (Increases => C); exit when not Set (C) or else C = Character'Last; C := Character'Succ (C); end loop; @@ -491,6 +494,7 @@ is pragma Loop_Invariant (for all Span of Max_Ranges (1 .. Range_Num) => (for all Char in Span.Low .. Span.High => Set (Char))); + pragma Loop_Variant (Increases => Range_Num); end loop; return Max_Ranges (1 .. Range_Num); diff --git a/gcc/ada/libgnat/a-strsea.adb b/gcc/ada/libgnat/a-strsea.adb --- a/gcc/ada/libgnat/a-strsea.adb +++ b/gcc/ada/libgnat/a-strsea.adb @@ -113,6 +113,7 @@ package body Ada.Strings.Search with SPARK_Mode is pragma Loop_Invariant (Num <= Ind - (Source'First - 1)); pragma Loop_Invariant (Ind >= Source'First); + pragma Loop_Variant (Increases => Ind); end loop; -- Mapped case @@ -142,6 +143,7 @@ package body Ada.Strings.Search with SPARK_Mode is null; pragma Loop_Invariant (Num <= Ind - (Source'First - 1)); pragma Loop_Invariant (Ind >= Source'First); + pragma Loop_Variant (Increases => Ind); end loop; end if; @@ -200,6 +202,7 @@ package body Ada.Strings.Search with SPARK_Mode is null; pragma Loop_Invariant (Num <= Ind - (Source'First - 1)); pragma Loop_Invariant (Ind >= Source'First); + pragma Loop_Variant (Increases => Ind); end loop; return Num;