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: Thomas.PAREAUD at astrium.eads.net (PAREAUD, Thomas)
- Date: Fri, 3 Apr 2009 09:25:55 +0200
- In-reply-to: <5EFD4D7AC6265F4D9D3A849CEA9219191AB169@LAXA.intra.cea.fr>
- 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> <5EFD4D7AC6265F4D9D3A849CEA9219191AB169@LAXA.intra.cea.fr>
Just for fun, I will say: /*@ loop invariant 0<=i<100; loop invariant \at(t[i], Pre) == 1 && t[i] == \at(t[i], Pre) + 1; */ for (i=0; i<100; i++) t[i]++; Do I win something??? :) -- Thomas P. -----Message d'origine----- De : frama-c-discuss-bounces at lists.gforge.inria.fr [mailto:frama-c-discuss-bounces at lists.gforge.inria.fr] De la part de CUOQ Pascal Envoy? : jeudi 2 avril 2009 20:38 ? : Frama-C public discussion; frama-c-discuss at lists.gforge.inria.fr Objet : Re: [Frama-c-discuss] "\at(var, Pre)" before a loop >> 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. _______________________________________________ Frama-c-discuss mailing list Frama-c-discuss at lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/frama-c-discuss Ce courriel (incluant ses eventuelles pieces jointes) peut contenir des informations confidentielles et/ou protegees ou dont la diffusion est restreinte. Si vous avez recu ce courriel par erreur, vous ne devez ni le copier, ni l'utiliser, ni en divulguer le contenu a quiconque. Merci d'en avertir immediatement l'expediteur et d'effacer ce courriel de votre systeme. Astrium decline toute responsabilite en cas de corruption par virus, d'alteration ou de falsification de ce courriel lors de sa transmission par voie electronique. This email (including any attachments) may contain confidential and/or privileged information or information otherwise protected from disclosure. If you are not the intended recipient, please notify the sender immediately, do not copy this message or any attachments and do not use it for any purpose or disclose its content to any person, but delete this message and any attachments from your system. Astrium disclaims any and all liability if this email transmission was virus corrupted, altered or falsified. --------------------------------------------------------------------- Astrium SAS (393 341 516 RCS Paris) - Siege social: 6 rue Laurent Pichat, 75016 Paris, France
- Follow-Ups:
- [Frama-c-discuss] Solution to yesterday's quizz
- From: Pascal.Cuoq at cea.fr (Pascal Cuoq)
- [Frama-c-discuss] Solution to yesterday's quizz
- 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] "\at(var, Pre)" before a loop
- From: Pascal.CUOQ at cea.fr (CUOQ Pascal)
- [Frama-c-discuss] Frama-C: GUI's response time
- Prev by Date: [Frama-c-discuss] "\at(var, Pre)" before a loop
- Next by Date: [Frama-c-discuss] Solution to yesterday's quizz
- Previous by thread: [Frama-c-discuss] "\at(var, Pre)" before a loop
- Next by thread: [Frama-c-discuss] Solution to yesterday's quizz
- Index(es):