CONTRACTS: Unwind transformed loops after loop contract transformation #7318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR unwinds transformed loops twice after applying loop contracts, so that users don't need to specify loop unwinding bounds for those loops. This PR will fix #7306.
Problem description
Currently, the loop contract transformation will insert a backward jump (https://github.com/diffblue/cbmc/blob/develop/src/goto-instrument/contracts/contracts.cpp#L110) into the result goto program. So after applying loop contracts, there will be loops that execute only one iteration in the place of the original annotated loops, which require users to correctly specify the unwinding bounds for them: either not unwinding them, or unwind them for at least twice. It is an unnecessary usability pain point for users. So backward goto should be avoided during loop contract transformation.
Example
A smaller example to illustrate the problem.
Note that the invariant
1 > 1
is invalid. So that a correct run of CBMC should report loop invariant doesn’t hold before entry of the loop.Run
goto-cc main.c
goto-instrument --apply-loop-contracts a.out b.out
to apply loop contracts and get the result goto programb.goto
. Then with commandcbmc b.out
(orcbmc --unwind 2 b.out
) CBMC will correctly report the failureHowever, running
cbmc --unwind 1 b.out
will report no failure.Running
cbmc --unwind 1 --unwinding-assertions b.out
will report