-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5198aef
commit 3612071
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
field f: Int | ||
|
||
predicate Mem(x: Ref) | ||
{ | ||
acc(x.f) && 0 <= x.f | ||
} | ||
|
||
function recurse(x: Ref, idx: Int): Int | ||
requires acc(Mem(x), wildcard) | ||
requires unfolding acc(Mem(x), wildcard) in 0 <= idx && idx <= x.f | ||
decreases unfolding acc(Mem(x), wildcard) in x.f - idx | ||
{ | ||
unfolding acc(Mem(x), wildcard) in idx == x.f ? 42 : recurse(x, idx + 1) | ||
} | ||
|
||
method fooUnsound(x: Ref) | ||
requires Mem(x) | ||
ensures Mem(x) | ||
//:: ExpectedOutput(postcondition.violated:assertion.false) | ||
ensures false // succeeds unexpectedly | ||
{ | ||
var oldResult: Int := recurse(x, 0) | ||
unfold Mem(x) | ||
x.f := x.f + 1 | ||
fold Mem(x) | ||
var newResult: Int := recurse(x, 0) // this call triggers the unsoundness | ||
} |