@@ -56,23 +56,56 @@ class code_contractst
56
56
57
57
void code_contracts (goto_functionst::goto_functiont &goto_function);
58
58
59
+ // / Applies (but does not check) a function contract.
60
+ // / This will assume that the contract holds, and then use that assumption
61
+ // / to remove the function call located at target.
62
+ // / \param goto_program The goto program containing the target callsite.
63
+ // / \param value_sets A value_setst object containing information about
64
+ // / aliasing in the goto program being analyzed
65
+ // / \param target An iterator pointing to the function call to be removed.
59
66
void apply_contract (
60
67
goto_programt &goto_program,
61
68
value_setst &value_sets,
62
69
goto_programt::targett target);
63
70
71
+ // / Applies (but does not check) a loop invariant.
72
+ // / This will assume that the loop invariant is indeed an invariant, and then
73
+ // / use that assumption to remove the loop.
74
+ // / \param goto_function The goto function containing the target loop.
75
+ // / \param value_sets A value_setst object containing information about
76
+ // / aliasing in the goto program being analyzed
77
+ // / \param loop_head An iterator pointing to the first instruction of the
78
+ // / target loop.
79
+ // / \param loop The loop being removed.
64
80
void apply_invariant (
65
81
goto_functionst::goto_functiont &goto_function,
66
82
value_setst &value_sets,
67
83
const goto_programt::targett loop_head,
68
84
const loopt &loop);
69
85
86
+ // / Checks (but does not apply) a function contract.
87
+ // / This will build a code snippet to be inserted at dest which will check
88
+ // that the function contract is satisfied.
89
+ // / \param function_id The id of the function being checked.
90
+ // / \param goto_function The goto_function object for the function
91
+ // / being checked.
92
+ // / \param dest An iterator pointing to the place to insert checking code.
70
93
void check_contract (
71
94
const irep_idt &function_id,
72
95
goto_functionst::goto_functiont &goto_function,
73
96
goto_programt &dest);
74
97
75
- void check_apply_invariant (
98
+ // / Checks and applies a loop invariant
99
+ // / This will replace the loop with a code snippet (based on the loop) which
100
+ // / will check that the loop invariant is indeed ian invariant, and then
101
+ // / use that invariant in what follows.
102
+ // / \param goto_function The goto function containing the target loop.
103
+ // / \param value_sets A value_setst object containing information about
104
+ // / aliasing in the goto program being analyzed
105
+ // / \param loop_head An iterator pointing to the first instruction of the
106
+ // / target loop.
107
+ // / \param loop The loop being removed.
108
+ void check_apply_invariant (
76
109
goto_functionst::goto_functiont &goto_function,
77
110
value_setst &value_sets,
78
111
const goto_programt::targett loop_head,
@@ -297,7 +330,7 @@ void code_contractst::apply_invariant(
297
330
inst->make_skip ();
298
331
}
299
332
300
- // Now havoc at the loop head. Use insert_swap to
333
+ // Now havoc at the loop head. Use insert_before_swap to
301
334
// preserve jumps to loop head.
302
335
goto_function.body .insert_before_swap (loop_head, havoc_code);
303
336
@@ -323,13 +356,15 @@ void code_contractst::check_contract(
323
356
return ;
324
357
}
325
358
326
- // build:
327
- // if(nondet)
359
+ // We build the following checking code :
360
+ // if(nondet) goto end
328
361
// decl ret
329
362
// decl parameter1 ...
330
363
// assume(requires) [optional]
331
364
// ret = function(parameter1, ...)
332
365
// assert(ensures)
366
+ // end:
367
+ // skip
333
368
334
369
// build skip so that if(nondet) can refer to it
335
370
goto_programt tmp_skip;
@@ -481,7 +516,7 @@ void code_contractst::check_apply_invariant(
481
516
a->source_location .set_comment (" Loop invariant violated before entry" );
482
517
}
483
518
484
- // havoc variables being written to
519
+ // havoc variables that can be modified by the loop
485
520
build_havoc_code (loop_head, modifies, havoc_code);
486
521
487
522
// assume the invariant
@@ -516,7 +551,7 @@ void code_contractst::check_apply_invariant(
516
551
loop_end->guard .make_not ();
517
552
}
518
553
519
- // Now havoc at the loop head. Use insert_swap to
554
+ // Now havoc at the loop head. Use insert_before_swap to
520
555
// preserve jumps to loop head.
521
556
goto_function.body .insert_before_swap (loop_head, havoc_code);
522
557
}
0 commit comments