I tried to verify a program with 2-D array and encountered a problem in the assigns clause.
On the sample code, I can prove the assigns clause in the function of init_2D_2.
But, I failed to prove the same assigns clause in the main function.
The main function does nothing but invokes init_2D_2 so I believe the assigns should be correct.
Can anyone show me why frama-c can't prove it?
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#define size 5
#define page 10
/*@
requires \valid( arr+(0..(size-1)) );
requires \valid( arr[0 .. (size-1)]+(0..(page-1)) );
assigns arr[0 .. (size-1)][0..(page-1)];
ensures \forall integer a,b; 0<=a<size && 0<=b<page ==> arr[a][b] == -1;
*/
void init_2D_2(int arr[size][page]){
/*@
loop invariant 0 <= i <= size;
loop invariant \forall integer a,b; 0<=a<i && 0<=b<page ==> arr[a][b] == -1;
loop assigns i, arr[0 .. (size-1)][0..(page-1)];
loop variant size - i;
*/
for(int i=0; i<size; i++) {
/*@
loop invariant 0 <= j <= page;
loop invariant \forall integer a,b; 0<=a<i && 0<=b<page ==> arr[a][b] == -1;
loop invariant \forall integer b; 0<=b<j ==> arr[i][b] == -1;
loop assigns j, arr[i][0..(page-1)];
loop variant page - j;
*/
for(int j=0; j<page; j++) {
arr[i][j] = -1;
}
}
}
int arr2_1[size][page];
/*@
requires \valid( arr2_1[0 .. (size-1)]+(0..(page-1)) );
assigns arr2_1[0 .. (size-1)][0 .. (page-1)];
ensures \forall integer a,b; 0<=a<size && 0<=b<page ==> arr2_1[a][b] == -1;
*/
void main(){
init_2D_2(arr2_1);
}
Frama-c result of main function
Frama-c result of init_2D_2 function
$ frama-c -wp -wp-rte test.c
[kernel] Parsing test.c (with preprocessing)
[rte:annot] annotating function init_2D_2
[rte:annot] annotating function main
[wp] 33 goals scheduled
[wp] [Alt-Ergo 2.4.1] Goal typed_main_assigns_normal : Timeout (Qed:10ms) (10s) (cached)
[wp] [Alt-Ergo 2.4.1] Goal typed_main_assigns_exit : Timeout (Qed:18ms) (10s) (cached)
[wp] [Cache] found:12
[wp] Proved goals: 31 / 33
Qed: 21 (0.67ms-21ms-62ms)
Alt-Ergo 2.4.1: 10 (18ms-40ms) (261) (interrupted: 2) (cached: 12)
$ frama-c -wp -wp-rte -wp-auto wp:split test.c
[kernel] Parsing test.c (with preprocessing)
[rte:annot] annotating function init_2D_2
[rte:annot] annotating function main
[wp] 33 goals scheduled
[wp] [Failed] Goal typed_main_assigns_exit
Alt-Ergo 2.4.1: Timeout (Qed:7ms) (10s) (cached)
Script: Timeout (Qed:3ms) (10s)
[wp] [Failed] Goal typed_main_assigns_normal
Alt-Ergo 2.4.1: Timeout (Qed:7ms) (10s) (cached)
Script: Timeout (Qed:3ms) (10s)
[wp] [Cache] found:14
[wp] Proved goals: 31 / 33
Qed: 21 (0.56ms-18ms-51ms)
Alt-Ergo 2.4.1: 10 (18ms-40ms) (261) (cached: 10)