Skip to content

Commit 4bd5c0a

Browse files
authored
Merge pull request #8470 from tautschnig/loop_entry-arrays
Contracts: document use of __CPROVER_loop_entry with arrays
2 parents bcda5a9 + 095413f commit 4bd5c0a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/goto-instrument/contracts/doc/user/contracts-history-variables.md

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ __CPROVER_loop_entry(*identifier*)
5353
5454
### Semantics
5555
`__CPROVER_loop_entry` takes a snapshot of the variable value right before the **first iteration** of the loop.
56+
Caveat: to create a snapshot of an array, cast the array variable (which is a
57+
pointer per C's type system) to a pointer-to-array, and then dereference.
58+
```c
59+
typedef int array_type[2];
60+
array_type var;
61+
__CPROVER_loop_invariant(__CPROVER_loop_entry(*(array_type*)var)[0] <= 42)
62+
```
5663

5764
### Example
5865
In this example the loop invariant asserts that `x <= 200` is upheld before and after every iteration of the `while` loop:

0 commit comments

Comments
 (0)