我试图了解VST如何处理(可寻址的)局部变量,所以我写了这个函数:
int main() {
int x = 5, y = 7;
int *a = &x;
int *b = &y;
*a = 8;
*b = 9;
return x;
}
然后我尝试使用以下规范进行验证:
Definition main_spec :=
DECLARE _main
WITH p : int (* still toying with things, couldn't figure out how to drop this *)
PRE [ ]
PROP ()
LOCAL ()
SEP ()
POST [ tint ]
EX i : Z,
PROP ( i = 8 )
LOCAL (temp ret_temp (Vint (Int.repr i)))
SEP ().
只要使用(forward
)直到返回语句可以证明以下内容,一切都会顺利进行
data_at Tsh tint (vint 9) v_y * data_at Tsh tint (vint 8) v_x |-- FF
这似乎是不可证明的(请注意,到目前为止,我刚刚应用了forward
)。我期待有一些说明,说明在局部变量被取消分配之后,堆是空的 ,即emp |-- emp
。
我可以在哪里找到有关此信息的更多信息?
谢谢!
其他信息:我挖掘了FF
后置条件的来源,它来自typecheck_expr
,尤其是Evar
的情况:
| Evar id ty =>
match access_mode ty with
| By_reference =>
match get_var_type Delta id with
| Some ty' =>
tc_bool (eqb_type ty ty')
(mismatch_context_type ty ty')
| None =>
tc_FF
(var_not_in_tycontext Delta id)
end
| _ => tc_FF (deref_byvalue ty) (* ?? *)
end
除非我读错了什么,否则这似乎表明您不能按值访问局部变量。这只是疏忽吗?还是语义上有什么阻止这种情况的发生?
答案 0 :(得分:0)
您正在使用哪个版本的VST?在最新的主分支版本(提交506f8e7)中,以下简单明了的证明就可以了。
Lemma body_main: semax_body Vprog Gprog f_main
main_spec.
Proof.
start_function.
forward.
forward.
forward.
forward.
forward.
forward.
forward.
forward.
Exists 8.
entailer!.
Qed.
答案 1 :(得分:0)
此失败的原因是您忘记了clightgen的if i*i in x:
标志。
如果您使用-normalize
而不是.c
来翻译clightgen -normalize
文件,它应该可以正常工作。