public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Julien Bortolussi <bortolussi@adacore.com>
Subject: [Ada] Fix a bug in the contract of formal ordered sets
Date: Tue, 6 Sep 2022 09:15:50 +0200	[thread overview]
Message-ID: <20220906071550.GA1280361@poulhies-Precision-5550> (raw)

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

There are 2 main issues in the postcondition of the function Replace
of the formal ordered sets, in the sub package Generic_Keys. One is
related to the fact that when the element is changed, the key is
also changed. The second one is due to the fact that the arrival of
the new element might modify the ordering of the set and thus
the Positions might be modified.
As a consequence, the postcondition might be false and thus fail
at runtime.

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

gcc/ada/

	* libgnat/a-cforse.ads (Replace): Fix the postcondition.

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

diff --git a/gcc/ada/libgnat/a-cforse.ads b/gcc/ada/libgnat/a-cforse.ads
--- a/gcc/ada/libgnat/a-cforse.ads
+++ b/gcc/ada/libgnat/a-cforse.ads
@@ -1598,7 +1598,7 @@ is
 
              --  Key now maps to New_Item
 
-             and Element (Container, Key) = New_Item
+             and Element (Container, Find (Container, Key)'Old) = New_Item
 
              --  New_Item is contained in Container
 
@@ -1622,8 +1622,9 @@ is
                     E_Right  => Elements (Container),
                     P_Left   => Positions (Container)'Old,
                     P_Right  => Positions (Container),
-                    Position => Find (Container, Key))
-             and Positions (Container) = Positions (Container)'Old;
+                    Position => Find (Container, Key)'Old)
+             and P.Keys_Included (Positions (Container),
+                                  Positions (Container)'Old);
 
       procedure Exclude (Container : in out Set; Key : Key_Type) with
         Global         => null,



                 reply	other threads:[~2022-09-06  7:15 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=20220906071550.GA1280361@poulhies-Precision-5550 \
    --to=poulhies@adacore.com \
    --cc=bortolussi@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).