首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证的软件工具链: if-then-else证明

验证的软件工具链: if-then-else证明
EN

Stack Overflow用户
提问于 2013-08-20 15:30:12
回答 2查看 504关注 0票数 3

我正在学习使用经过验证的软件工具链(VST)。我被困在证明一个简单的"if-then-else“代码块上。

下面是.c文件:

代码语言:javascript
复制
int iftest(int a){
   int r=0; 
   if(a==2){
      r=0;
   else{
      r=0;
   }
return r;
}

我写了一个关于iftest()的规范,如下所示:

代码语言:javascript
复制
Definition if_spec :=`
DECLARE _iftest`
      WITH a0:int
                PRE [_a OF tint]
                PROP ()
                LOCAL (`(eq (Vint a0)) (eval_id _a))
                SEP ()
                POST [tint]
                PROP ()
                LOCAL ((`(eq (Vint (Int.repr 0))) retval))
                SEP ().`

验证步骤如下:

Lemma body_iftest : semax_body Vprog Gtot f_iftest if_spec.Proof. start_function. name a _a. name r _r. forward. (*r=0*) simplify_typed_comparison. forward. (*if(E)*). go_lower. subst. normalize.

它产生了一个假设:Post := EX x : ?214, ?215 x : environ -> mpred和"then“子句不能由"go_lower”和"normalize“继续。

EN

回答 2

Stack Overflow用户

发布于 2015-01-12 02:24:43

在当前版本的VST中,有一种forward_if PRED策略。下面是你如何使用它来解决你的目标:

代码语言:javascript
复制
Require Import floyd.proofauto.
Require Import iftest.

Local Open Scope logic.
Local Open Scope Z.

Definition if_spec :=
  DECLARE _iftest
      WITH a0:int
                PRE [_a OF tint]
                PROP ()
                LOCAL (`(eq (Vint a0)) (eval_id _a))
                SEP ()
                POST [tint]
                PROP ()
                LOCAL ((`(eq (Vint (Int.repr 0))) retval))
                SEP ().

Definition Vprog : varspecs := nil.
Definition Gtot : funspecs := if_spec :: nil.

Lemma body_iftest : semax_body Vprog Gtot f_iftest if_spec.
Proof.
  start_function.
  name a _a.
  name r _r.
  forward.
  forward_if (PROP ()
                   LOCAL (`(eq (Vint (Int.repr 0))) (eval_id _r)) SEP()). 
  + forward.
    entailer.
  + forward.
    entailer.
  + forward.
Qed.

另外,在else之前,@bazza关于}丢失的说法是对的。我想它已经修好了。

票数 1
EN

Stack Overflow用户

发布于 2013-08-28 06:10:11

这可能是一个没有帮助的答案,但我不禁注意到你的.c代码有3个{而只有2个},这表明它无法编译。你收到的错误消息会不会与此有关?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18329313

复制
相关文章

相似问题

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