Skip to content

Commit 8101fe1

Browse files
authored
Merge pull request #681 from viperproject/meilers_term_pred_fix
Two fixes for VerifyThis issues
2 parents 6e2ce95 + cb4f1e5 commit 8101fe1

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/main/scala/viper/silver/ast/Program.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ case class Function(name: String, formalArgs: Seq[LocalVarDecl], typ: Type, pres
464464
Seq(ConsistencyError("Function post-conditions must not have old expressions.", p.pos)) else Seq()}) ++
465465
(pres ++ posts).flatMap(Consistency.checkNoPermForpermExceptInhaleExhale) ++
466466
(if(!(body forall (_ isSubtype typ))) Seq(ConsistencyError("Type of function body must match function type.", pos)) else Seq() ) ++
467+
(posts flatMap (p => if (!Consistency.noPerm(p) || !Consistency.noForPerm(p)) Seq(ConsistencyError("perm and forperm expressions are not allowed in function postconditions", p.pos)) else Seq() )) ++
467468
pres.flatMap(Consistency.checkPre) ++
468469
posts.flatMap(Consistency.checkPost) ++
469470
posts.flatMap(p => if (!Consistency.noPermissions(p))

src/main/scala/viper/silver/plugin/standard/termination/TerminationPlugin.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class TerminationPlugin(@unused reporter: viper.silver.reporter.Reporter,
7979
case pc@PCall(idnUse, args, None) if input.predicates.exists(_.idndef.name == idnUse.name) =>
8080
// PCall represents the predicate access before the translation into the AST
8181
PPredicateInstance(args, idnUse)(pc.pos)
82+
case PAccPred(pa@PPredicateAccess(args, idnuse), _) => PPredicateInstance(args, idnuse)(pa.pos)
83+
case PAccPred(pc@PCall(idnUse, args, None), _) if input.predicates.exists(_.idndef.name == idnUse.name) =>
84+
PPredicateInstance(args, idnUse)(pc.pos)
8285
case d => d
8386
}).recurseFunc({
8487
case PUnfolding(_, exp) => // ignore predicate access when it is used for unfolding

src/test/resources/all/permission_introspection/forpermCheck.vpr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
field f1: Int
55

6+
function permInPost(x: Ref): Int
7+
//:: ExpectedOutput(consistency.error)
8+
ensures [perm(x.f1) == none, true]
9+
610
method permUse()
711
{
812
var r1: Ref

src/test/resources/termination/methods/basic/someTypes.vpr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,29 @@ method predicateTest2(xs: Ref)
3333
fold list(xs)
3434
//:: ExpectedOutput(termination.failed:tuple.false)
3535
predicateTest2(xs)
36+
}
37+
38+
method predicateTest3(xs: Ref)
39+
requires acc(list(xs), 2/3)
40+
decreases acc(list(xs), 2/3)
41+
ensures acc(list(xs), 2/3)
42+
{
43+
unfold acc(list(xs), 2/3)
44+
if (xs.next != null) {
45+
predicateTest3(xs.next)
46+
}
47+
fold acc(list(xs), 2/3)
48+
}
49+
50+
method predicateTest4(xs: Ref)
51+
requires acc(list(xs), 2/3)
52+
decreases acc(list(xs), 2/3)
53+
ensures acc(list(xs), 2/3)
54+
{
55+
unfold acc(list(xs), 2/3)
56+
if (xs.next != null) {
57+
}
58+
fold acc(list(xs), 2/3)
59+
//:: ExpectedOutput(termination.failed:tuple.false)
60+
predicateTest4(xs)
3661
}

0 commit comments

Comments
 (0)