Skip to content

Contracts: document use of __CPROVER_loop_entry with arrays #8470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ __CPROVER_loop_entry(*identifier*)

### Semantics
`__CPROVER_loop_entry` takes a snapshot of the variable value right before the **first iteration** of the loop.
Caveat: to create a snapshot of an array, cast the array variable (which is a
pointer per C's type system) to a pointer-to-array, and then dereference.
```c
typedef int array_type[2];
array_type var;
__CPROVER_loop_invariant(__CPROVER_loop_entry(*(array_type*)var)[0] <= 42)
```

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