假设我们有以下 C 注释代码:
#define L 3
int a[L] = {0};
/*@ requires \valid(a+(0..(L - 1)));
ensures \forall int j; 0 <= j < L ==> (a[j] == j); */
int main() {
int i = 0;
/*@ loop assigns i, a[0..(i-1)];
loop invariant inv1: 0 <= i <= L;
loop invariant inv2:
\forall int k; 0 <= k < i ==> a[k] == k;
*/
while (i < L) {
a[i] = i;
i++;
}
/*@ assert final_progress:
\forall int k; 0 < k < L ==> a[k] == a[k-1] + 1;
assert final_c:
a[2] == a[1] - 1; */
return 0;
}
尽管 final_progress 语句已被证明,为什么 Alt-Ergo/Z3 会为 final_c 断言产生“未知”或超时?对于这种明显(从用户的角度)无效的陈述,我肯定希望看到“无效”。
$ frama-c -wp -wp-rte -wp-prover z3 test2.c
..
[wp] [z3] Goal typed_main_assert_final_c : Unknown (455ms)
$ frama-c -wp -wp-rte -wp-prover alt-ergo test2.c
..
[wp] [Alt-Ergo] Goal typed_main_assert_final_c : Timeout