I'm trying to prove a while-loop with a pointer assign in frama-c. Unfortunately, I encounter problems. I've managed to prove it if rewriting the code under test with a for-loop and with array notation. Does anyone have any ideas on how to prove this?
Code I want to prove:
/*@
requires \valid(v+(0..n-1));
requires v != \null;
requires n > 0;
assigns v[0..n-1];
ensures \forall integer q; 0<=q<=n-1 ==> v[q]==(unsigned char)0;
*/
static void make_zero( unsigned char *v, size_t n ) {
volatile unsigned char *p = (unsigned char*)v;
/*@
loop invariant 0 <= n <= \at(n, Pre);
loop invariant \forall integer j; 0 <= j < (\at(n, Pre)-n) ==> \at(p, Pre)[j] == (unsigned char)0;
loop assigns n, p;
loop variant n; */
while( n-- ){
*p++ = 0;
}
}
Rewritten code:
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer j; 0 < j < i ==> p[j] == (unsigned char)0;
loop assigns i, p[0..n-1];
loop variant n-i;
*/
for(size_t i = 0; i<n; i++){
p[i] = 0;
}