我的简单程序是vars.c
:
int pure0 ()
{
return 0;
}
int get0(int* arr)
{
int z = pure0();
return z;
}
我开始证明(文件verif_vars.c
):
Require Import floyd.proofauto.
Require Import vars.
Local Open Scope logic.
Local Open Scope Z.
Definition get0_spec :=
DECLARE _get0
WITH sh : share, arr : Z->val, varr : val
PRE [_arr OF (tptr tint)]
PROP ()
LOCAL (`(eq varr) (eval_id _arr);
`isptr (eval_id _arr))
SEP (`(array_at tint sh arr 0 100) (eval_id _arr))
POST [tint] `(array_at tint sh arr 0 100 varr) &&
local(`(eq (Vint (Int.repr 0))) retval).
Definition pure0_spec :=
DECLARE _pure0
WITH sh : share
PRE []
PROP ()
LOCAL ()
SEP ()
POST [tint] local(`(eq (Vint (Int.repr 0))) retval).
Definition Vprog : varspecs := nil.
Definition Gprog : funspecs := get0_spec :: pure0_spec ::nil.
Lemma body_pure0: semax_body Vprog Gprog f_pure0 pure0_spec.
Proof.
start_function.
forward.
Qed.
Lemma body_get0: semax_body Vprog Gprog f_get0 get0_spec.
Proof.
start_function.
name arrarg _arr.
name zloc _z.
name zloc' _z'.
forward_call (sh).
entailer!.
auto with closed.
after_call.
forward.
entailer!.
最后有两个子目标:
Espec : OracleKind
sh : share
arr : Z -> val
Struct_env := abbreviate : type_id_env.type_id_env
Delta := abbreviate : tycontext
zloc0 : val
arrarg : val
zloc : int
TC : is_pointer_or_null arrarg
Parrarg : isptr arrarg
============================
Int.repr 0 = zloc
subgoal 2 (ID 1273) is:
!!(Int.repr 0 = zloc) |-- emp
- 第一个直接来自
pure0_spec
后置条件。但是我怎么能告诉 Coq 呢? - 第二个目标可以简化(由
admit. entailer.
)为TT |-- emp
。这似乎又是微不足道的,但仍然如何证明它(SearchAbout derives
并且SearchAbout emp
不显示任何一般引理)?
我使用:VST 1.5(2014-10-02 时为 6834P)、CompCert 2.4、Coq 8.4pl3(Jan'14)和 OCaml 4.01.0。