Frama-C-discuss mailing list archives
This page gathers the archives of the old Frama-C-discuss archives, that was hosted by Inria's gforge before its demise at the end of 2020. To search for mails newer than September 2020, please visit the page of the new mailing list on Renater.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Frama-c-discuss] "\at(var, Pre)" before a loop
- Subject: [Frama-c-discuss] "\at(var, Pre)" before a loop
- From: Pascal.CUOQ at cea.fr (CUOQ Pascal)
- Date: Thu, 2 Apr 2009 20:37:56 +0200
- References: <A6FD74D4A6DA4247AD801E3943634063034C343A@sctex002.st-cloud.dassault-avion.fr><5030C1BB-9A4C-458A-B0CB-DA49C3EABB13@cea.fr><1238682330.7692.339.camel@localhost><3d13dcfc0904020731y7bfae28fo750d100e0fbccf40@mail.gmail.com><1238683464.7692.346.camel@localhost><F1229212CB084F4CBEA197909C8699F1021BD9B5@TLSMAIL1.tls.fr.astrium.corp> <20090402183459.41f3b1dd@is005115>
>> In other words, is this loop invariant correct? > >\at(expr,Pre) always denotes the value of expr in the pre-state of the >function (i.e. when the function is entered). Assuming there's no >overflow or invalid pointer access, the loop invariant is correct. On the subject of the two caveats expressed by Virgile, I would like to add this: 1/ when you subtract two valid pointers with the same base address, the result is never an overflow, so do not worry about that and worry about the validity instead. 2/ Your function presumably has a precondition that looks like "\valid_range(pString, 0, nbBytes)" (perhaps +/-1, I never know). If I was you and if I wasn't able to prove the correctness of my function, one of the things I would try first would be to replicate that precondition inside the invariant: loop invariant i == pString - \at(pString, Pre) && \valid_range(\at(pString, Pre), 0, nbBytes) ; As Virgile explained in another thread, loops are very much treated as opaque blocks by those analyzers that are based on Hoare logic. If you need a property after or even inside the loop, you usually need to put it in the loop invariant, even if it's orthogonal to what the loop does (and it's very easy to forget in this case). Actually it's so annoying that most analyzers try to save you the writing of these parts of the invariant, hence my reserves. It may not be necessary with Jessie. But it doesn't hurt to try. Here's a fun little exercice on the same topic : if you have the property that every cell in an int array t[100] contains 1, what is the invariant for proving that every cell contains 2 after executing the following loop: for (i=0; i<100; i++) t[i]++; Pascal PS: solution in my next post.
- Follow-Ups:
- [Frama-c-discuss] "\at(var, Pre)" before a loop
- From: Thomas.PAREAUD at astrium.eads.net (PAREAUD, Thomas)
- [Frama-c-discuss] "\at(var, Pre)" before a loop
- References:
- [Frama-c-discuss] Frama-C: GUI's response time
- From: Dillon.Pariente at dassault-aviation.com (Pariente Dillon)
- [Frama-c-discuss] Frama-C: GUI's response time
- From: Pascal.Cuoq at cea.fr (Pascal Cuoq)
- [Frama-c-discuss] Frama-C: GUI's response time
- From: julien.signoles at cea.fr (Julien Signoles)
- [Frama-c-discuss] Frama-C: GUI's response time
- From: dmentre at linux-france.org (David MENTRE)
- [Frama-c-discuss] Frama-C: GUI's response time
- From: julien.signoles at cea.fr (Julien Signoles)
- [Frama-c-discuss] "\at(var, Pre)" before a loop
- From: Thomas.PAREAUD at astrium.eads.net (PAREAUD, Thomas)
- [Frama-c-discuss] "\at(var, Pre)" before a loop
- From: virgile.prevosto at cea.fr (Virgile Prevosto)
- [Frama-c-discuss] Frama-C: GUI's response time
- Prev by Date: [Frama-c-discuss] \base_addr and Jessie
- Next by Date: [Frama-c-discuss] "\at(var, Pre)" before a loop
- Previous by thread: [Frama-c-discuss] \base_addr and Jessie
- Next by thread: [Frama-c-discuss] "\at(var, Pre)" before a loop
- Index(es):