Skip to content

Commit 2efe5b2

Browse files
committed
reject contracts on do/while loops for now
Whether the first (unguarded) loop iteration should be executed "before" the base case assertion or not is still under discussion. Loop contracts on do/while loops are rejected until this is resolved.
1 parent 6426025 commit 2efe5b2

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
int x = 0;
6+
7+
do
8+
{
9+
x++;
10+
} while(x < 10) __CPROVER_loop_invariant(0 <= x && x <= 10);
11+
12+
assert(x == 10);
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KNOWNBUG
2+
main.c
3+
--apply-loop-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
This test checks that loop contracts work correctly on do/while loops.

src/goto-instrument/contracts/contracts.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,14 @@ void code_contractst::check_apply_loop_contracts(
236236
new_decreases_vars.push_back(new_decreases_var);
237237
}
238238

239-
// non-deterministically skip the loop if it is a do-while loop.
240239
// TODO: Fix loop contract issues for do/while loops.
241240
if(!loop_head->is_goto())
242241
{
242+
log.error() << "Loop contracts are unsupported on do/while loops: "
243+
<< loop_head->source_location() << messaget::eom;
244+
throw 0;
245+
246+
// non-deterministically skip the loop if it is a do-while loop.
243247
generated_code.add(goto_programt::make_goto(
244248
loop_end,
245249
side_effect_expr_nondett(bool_typet(), loop_head->source_location())));

0 commit comments

Comments
 (0)