@@ -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,
@@ -298,7 +331,7 @@ void code_contractst::apply_invariant(
298
331
inst->make_skip ();
299
332
}
300
333
301
- // Now havoc at the loop head. Use insert_swap to
334
+ // Now havoc at the loop head. Use insert_before_swap to
302
335
// preserve jumps to loop head.
303
336
goto_function.body .insert_before_swap (loop_head, havoc_code);
304
337
@@ -324,13 +357,15 @@ void code_contractst::check_contract(
324
357
return ;
325
358
}
326
359
327
- // build:
328
- // if(nondet)
360
+ // We build the following checking code :
361
+ // if(nondet) goto end
329
362
// decl ret
330
363
// decl parameter1 ...
331
364
// assume(requires) [optional]
332
365
// ret = function(parameter1, ...)
333
366
// assert(ensures)
367
+ // end:
368
+ // skip
334
369
335
370
// build skip so that if(nondet) can refer to it
336
371
goto_programt tmp_skip;
@@ -482,7 +517,7 @@ void code_contractst::check_apply_invariant(
482
517
a->source_location .set_comment (" Loop invariant violated before entry" );
483
518
}
484
519
485
- // havoc variables being written to
520
+ // havoc variables that can be modified by the loop
486
521
build_havoc_code (loop_head, modifies, havoc_code);
487
522
488
523
// assume the invariant
@@ -517,7 +552,7 @@ void code_contractst::check_apply_invariant(
517
552
loop_end->guard .make_not ();
518
553
}
519
554
520
- // Now havoc at the loop head. Use insert_swap to
555
+ // Now havoc at the loop head. Use insert_before_swap to
521
556
// preserve jumps to loop head.
522
557
goto_function.body .insert_before_swap (loop_head, havoc_code);
523
558
}
0 commit comments