首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在保存返回值的变量上使用retval-post条件?

如何在保存返回值的变量上使用retval-post条件?
EN

Stack Overflow用户
提问于 2015-01-18 18:48:40
回答 1查看 148关注 0票数 0

我的简单程序是vars.c

代码语言:javascript
复制
int pure0 ()
{
    return 0;
}

int get0(int* arr)
{
    int z = pure0();
    return z;
}

我开始验证(文件verif_vars.c):

代码语言:javascript
复制
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!.

最后有了两个子目标:

代码语言:javascript
复制
  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 derivesSearchAbout emp没有显示任何一般的引理)?

我使用:VST1.5(在2014-10-02年为6834P),CompCert 2.4,Coq 8.4pl3(1月14日)和OCaml 4.01.0。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-18 19:13:06

第一:草率地,不尝试自己复制--是否可能使用entailer!太“冒险”,因为(如文档所示) entailer!有时会将可证明的目标转化为不可证明的目标。试着在没有爆炸的情况下使用entailer,看看它是否更好看。

第二,TT |-- emp不是真的。TT适用于任何堆,而emp只应用于空堆。可以通过将pure函数的后置条件更改为

代码语言:javascript
复制
POST [tint] local(`(eq (Vint (Int.repr 0))) retval) && emp.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28013427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档