public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Yannick Moy <moy@adacore.com>
Subject: [Ada] Facilitate proof of Overwrite in bounded strings library
Date: Fri, 13 May 2022 08:07:43 +0000	[thread overview]
Message-ID: <20220513080743.GA2508413@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 560 bytes --]

Consistently use >= operator in both the code and contracts of
function/procedure Overwrite, to facilitate proof, instead of the strict
inequality > sometimes, as only New_Item remains in the result in the
case of equal size too.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/a-strbou.ads (Overwrite): Switch to >= operator in
	contracts.
	* libgnat/a-strsup.adb (Super_Overwrite): Switch to >= operator
	in code of procedure (function already uses it).
	* libgnat/a-strsup.ads (Super_Overwrite): Switch to >= operator
	in contracts.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2289 bytes --]

diff --git a/gcc/ada/libgnat/a-strbou.ads b/gcc/ada/libgnat/a-strbou.ads
--- a/gcc/ada/libgnat/a-strbou.ads
+++ b/gcc/ada/libgnat/a-strbou.ads
@@ -1898,7 +1898,7 @@ package Ada.Strings.Bounded with SPARK_Mode is
                --  some characters of Source are remaining at the left.
 
                and then
-                 (if New_Item'Length > Max_Length then
+                 (if New_Item'Length >= Max_Length then
 
                     --  New_Item covers all Max_Length characters
 
@@ -1984,7 +1984,7 @@ package Ada.Strings.Bounded with SPARK_Mode is
                --  some characters of Source are remaining at the left.
 
                and then
-                 (if New_Item'Length > Max_Length then
+                 (if New_Item'Length >= Max_Length then
 
                     --  New_Item covers all Max_Length characters
 


diff --git a/gcc/ada/libgnat/a-strsup.adb b/gcc/ada/libgnat/a-strsup.adb
--- a/gcc/ada/libgnat/a-strsup.adb
+++ b/gcc/ada/libgnat/a-strsup.adb
@@ -1226,7 +1226,7 @@ package body Ada.Strings.Superbounded with SPARK_Mode is
                  (New_Item (New_Item'First .. New_Item'Last - Droplen));
 
             when Strings.Left =>
-               if New_Item'Length > Max_Length then
+               if New_Item'Length >= Max_Length then
                   Source.Data (1 .. Max_Length) := Super_String_Data
                     (New_Item
                       (New_Item'Last - Max_Length + 1 .. New_Item'Last));


diff --git a/gcc/ada/libgnat/a-strsup.ads b/gcc/ada/libgnat/a-strsup.ads
--- a/gcc/ada/libgnat/a-strsup.ads
+++ b/gcc/ada/libgnat/a-strsup.ads
@@ -2000,7 +2000,7 @@ package Ada.Strings.Superbounded with SPARK_Mode is
             --  Source are remaining at the left.
 
             and then
-              (if New_Item'Length > Source.Max_Length then
+              (if New_Item'Length >= Source.Max_Length then
 
                  --  New_Item covers all Max_Length characters
 
@@ -2089,7 +2089,7 @@ package Ada.Strings.Superbounded with SPARK_Mode is
             --  Source are remaining at the left.
 
             and then
-              (if New_Item'Length > Source.Max_Length then
+              (if New_Item'Length >= Source.Max_Length then
 
                  --  New_Item covers all Max_Length characters
 



                 reply	other threads:[~2022-05-13  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220513080743.GA2508413@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=moy@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).