Skip to content

Commit 95f4a47

Browse files
author
Daniel Kroening
committed
big change: cbmc now uses --all-properties as the default
1 parent b4f3819 commit 95f4a47

File tree

18 files changed

+101
-51
lines changed

18 files changed

+101
-51
lines changed

doc/html-manual/cbmc.shtml

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ domains</a>. More detail on automatically generated properties is provided
5959
<a href="properties.shtml">here</a>.</p>
6060

6161
<p class="justified">
62-
Note that automatically generated properties need not necessarily correspond
63-
to bugs &ndash; these are just <i>potential</i> flaws, as abstract
64-
interpretation might be imprecise. Whether one of these properties
65-
holds or corresponds to a bug needs to be determined by further analysis.
62+
Note that these automatically generated properties need not necessarily
63+
correspond to bugs &ndash; these are just <i>potential</i> flaws, as
64+
abstract interpretation might be imprecise. Whether these properties
65+
hold or correspond to actual bugs needs to be determined by further analysis.
6666
</p>
6767

6868
<p class="justified">
@@ -87,17 +87,40 @@ holds. Let's run the decision procedure:</p>
8787
</code>
8888

8989
<p class="justified">
90-
CBMC transforms the equation you have seen before into CNF and passes it
91-
to a SAT solver (more background on this step is in the book
92-
on <a href="http://www.decision-procedures.org/">Decision Procedures</a>).
93-
CBMC can now detect that the equation is actually not valid,
94-
and thus, there is a bug in the program. It prints a counterexample trace,
95-
i.e., a program trace that ends in a state which violates the property. In
96-
our example, the program trace ends in the faulty array access. It also
97-
shows the values the input variables must have for the bug to occur. In this
98-
example, <code>argc</code> must be one to trigger the out-of-bounds array access.
99-
If you add a branch to the example that requires that <code>argc&gt;=3</code>,
100-
the bug is fixed and CBMC will report a successful verification run.</p>
90+
CBMC transforms the equation you have seen before into CNF and passes it to
91+
a SAT solver (more background on this step is in the book on <a
92+
href="http://www.decision-procedures.org/">Decision Procedures</a>). It
93+
then determines which of the properties that it has generated for the
94+
program hold and which do not. Using the SAT solver, CBMC detects that the
95+
property for the object bounds of <code>argv</code> does not hold, and will
96+
thus print a line as follows:
97+
</p>
98+
99+
<code>
100+
[main.pointer_dereference.6] dereference failure: object bounds in argv[(signed long int)2]: FAILED
101+
</code>
102+
103+
<h3>Counterexample Traces</h3>
104+
105+
<p class="justified">
106+
Let us have a closer look at this property and why it fails. To aid the
107+
understanding of the problem, CBMC can generate a <i>counterexample
108+
trace</i> for failed properties. To obtain this trace, run
109+
</P
110+
111+
<code>
112+
&nbsp;&nbsp;cbmc file1.c --bounds-check --pointer-check --property main.pointer_dereference.6
113+
</code>
114+
115+
<p class="justified">
116+
CBMC then prints a counterexample trace, i.e., a program trace that begins
117+
with <code>main</code> and ends in a state which violates the property. In
118+
our example, the program trace ends in the faulty array access. It also
119+
shows the values the input variables must have for the bug to occur. In
120+
this example, <code>argc</code> must be one to trigger the out-of-bounds
121+
array access. If you add a branch to the example that requires that
122+
<code>argc&gt;=3</code>, the bug is fixed and CBMC will report that all
123+
properties are OK.</p>
101124

102125
<h3>Verifying Modules</h3>
103126

@@ -129,14 +152,21 @@ In order to set the entry point to the <code>sum</code> function, run
129152
&nbsp;&nbsp;cbmc file2.c --function sum --bounds-check
130153
</code>
131154

155+
<p class="justified">
156+
It is often necessary to build a suitable <i>harness</i> for the function
157+
in order to set up the environment appropriately.
158+
</p>
159+
132160
<h3>Loop Unwinding</h3>
133161

134162
<p class="justified">
135-
You will note that CBMC unwinds the <code>for</code> loop in the program.
136-
As CBMC performs Bounded Model Checking, all loops have to have a finite
137-
upper run-time bound in order to guarantee that all bugs are found. CBMC
138-
can optionally check that enough unwinding is performed. As an example, consider
139-
the program <a href="binsearch.c">binsearch.c</a>:</p>
163+
When running the previous example, you will have noted that CBMC unwinds the
164+
<code>for</code> loop in the program. As CBMC performs Bounded Model
165+
Checking, all loops have to have a finite upper run-time bound in order to
166+
guarantee that all bugs are found. CBMC can optionally check that enough
167+
unwinding is performed. As an example, consider the program <a
168+
href="binsearch.c">binsearch.c</a>:
169+
</p>
140170

141171
<hr>
142172
<code>
@@ -171,10 +201,13 @@ command line argument:</p>
171201
<p class="justified">
172202
CBMC verifies that verifies the array accesses are within the bounds; note
173203
that this actually depends on the result of the right shift. In addition,
174-
as CBMC is given the option <code>--unwinding-assertions</code>, it also
175-
checks that enough unwinding is done, i.e., it proves a run-time bound. For
176-
any lower unwinding bound, there are traces that require more loop
177-
iterations. Thus, CBMC will produce an appropriate counterexample.
204+
as CBMC is given the option
205+
<nobr><code>--unwinding-assertions</code></nobr>, it also checks that enough
206+
unwinding is done, i.e., it proves a run-time bound. For any lower
207+
unwinding bound, there are traces that require more loop iterations. Thus,
208+
CBMC will report that the unwinding assertion has failed. As usual, a counterexample
209+
trace that documents this can be obtained with the option
210+
<code>--property</code>.
178211
</p>
179212

180213
<h3>Unbounded Loops</h3>
@@ -244,7 +277,7 @@ the number of program steps to be processed.</li>
244277
Given the option <code>--unwinding-assertions</code>, CBMC checks whether
245278
the arugment to <code>--unwind</code> is large enough to cover all program
246279
paths. If the argument is too small, CBMC will detect that not enough
247-
unwinding is done and aborts with an unwinding assertion violation.
280+
unwinding is done reports that an unwinding assertion has failed.
248281
</p>
249282

250283
<p class="justified">

regression/cbmc/Free1/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33
--pointer-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^Counterexample:$
76
^VERIFICATION FAILED$
87
--
98
^warning: ignoring

regression/cbmc/Free2/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33
--pointer-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^Counterexample:$
76
^VERIFICATION FAILED$
87
--
98
^warning: ignoring

regression/cbmc/Free3/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CORE
22
main.c
33
--pointer-check
44
^SIGNAL=0$
5-
^Counterexample:$
65
^VERIFICATION FAILED$
76
--
87
^warning: ignoring

regression/cbmc/Free4/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CORE
22
main.c
33
--pointer-check
44
^SIGNAL=0$
5-
^Counterexample:$
65
^VERIFICATION FAILED$
76
--
87
^warning: ignoring

regression/cbmc/Function5/test.desc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ main.c
33
--pointer-check --bounds-check
44
^SIGNAL=0$
55
^EXIT=10$
6-
^Counterexample:$
7-
^ dereference failure: object bounds in .*$
8-
^VERIFICATION FAILED$
6+
^\[.*\] dereference failure: object bounds in \*p: FAILED$
97
--
108
^warning: ignoring

regression/cbmc/Overflow_Addition1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--signed-overflow-check
44
^SIGNAL=0$
5-
^Counterexample:$
5+
^\[.*\] arithmetic overflow on signed + in .*: FAILED$
66
^VERIFICATION FAILED$
77
--
88
^warning: ignoring

regression/cbmc/Pointer_Arithmetic5/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CORE
22
main.c
33
--pointer-check --bounds-check --function f
44
^SIGNAL=0$
5-
^Counterexample:$
65
^VERIFICATION FAILED$
76
--
87
^warning: ignoring

regression/cbmc/Pointer_Arithmetic8/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CORE
22
main.c
33
--pointer-check --bounds-check
44
^SIGNAL=0$
5-
^Counterexample:$
65
^VERIFICATION FAILED$
76
--
87
^warning: ignoring

regression/cbmc/String2/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33
--pointer-check --bounds-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^Counterexample:$
76
^VERIFICATION FAILED$
87
--
98
^warning: ignoring

regression/cbmc/Undefined_Function1/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33

44
^SIGNAL=0$
55
^\*\*\*\* WARNING: no body for function f$
6-
^Counterexample:$
76
^VERIFICATION FAILED$
87
--
98
^warning: ignoring

regression/cbmc/Undefined_Function2/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33

44
^SIGNAL=0$
55
^\*\*\*\* WARNING: no body for function asd$
6-
^Counterexample:$
76
^VERIFICATION FAILED$
87
--
98
^warning: ignoring

regression/cbmc/goto4/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--unwind 1 --unwinding-assertions
44
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION FAILED$
7-
^ unwinding assertion loop 0$
6+
^\[.*] assertion g == 0: OK$
7+
^\[.*] unwinding assertion loop 0: FAILED$
88
--
99
^warning: ignoring

src/cbmc/all_properties.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ safety_checkert::resultt bmc_all_propertiest::operator()()
259259
<< cover_goals.iterations() << " iteration"
260260
<< (cover_goals.iterations()==1?"":"s")
261261
<< ")" << eom;
262+
263+
bool safe=(cover_goals.number_covered()==0);
264+
265+
if(safe)
266+
bmc.report_success(); // legacy, might go away
267+
else
268+
bmc.report_failure(); // legacy, might go away
262269

263-
return (cover_goals.number_covered()==0)?
264-
safety_checkert::SAFE:safety_checkert::UNSAFE;
270+
return safe?safety_checkert::SAFE:safety_checkert::UNSAFE;
265271
}
266272

267273
/*******************************************************************\

src/cbmc/bmc.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,28 @@ safety_checkert::resultt bmct::decide(
557557
{
558558
prop_conv.set_message_handler(get_message_handler());
559559

560-
if(options.get_bool_option("all-properties"))
560+
if(options.get_bool_option("stop-on-fail"))
561+
return stop_on_fail(goto_functions, prop_conv);
562+
else
561563
return all_properties(goto_functions, prop_conv);
564+
}
565+
566+
/*******************************************************************\
567+
568+
Function: bmct::stop_on_fail
569+
570+
Inputs:
571+
572+
Outputs:
573+
574+
Purpose:
575+
576+
\*******************************************************************/
562577

578+
safety_checkert::resultt bmct::stop_on_fail(
579+
const goto_functionst &goto_functions,
580+
prop_convt &prop_conv)
581+
{
563582
switch(run_decision_procedure(prop_conv))
564583
{
565584
case decision_proceduret::D_UNSATISFIABLE:

src/cbmc/bmc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class bmct:public safety_checkert
9292
virtual resultt all_properties(
9393
const goto_functionst &goto_functions,
9494
prop_convt &solver);
95+
virtual resultt stop_on_fail(
96+
const goto_functionst &goto_functions,
97+
prop_convt &solver);
9598
virtual void show_vcc(std::ostream &out);
9699
virtual void show_program();
97100
virtual void report_success();

src/cbmc/cbmc_parse_options.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
177177
else
178178
options.set_option("simplify", true);
179179

180-
if(cmdline.isset("all-claims") || // will go away
181-
cmdline.isset("all-properties")) // use this one
182-
options.set_option("all-properties", true);
180+
if(cmdline.isset("stop-on-fail") ||
181+
cmdline.isset("property"))
182+
options.set_option("stop-on-fail", true);
183183
else
184-
options.set_option("all-properties", false);
184+
options.set_option("stop-on-fail", false);
185185

186186
if(cmdline.isset("unwind"))
187187
options.set_option("unwind", cmdline.get_value("unwind"));
@@ -1060,8 +1060,9 @@ void cbmc_parse_optionst::help()
10601060
" cbmc file.c ... source file names\n"
10611061
"\n"
10621062
"Analysis options:\n"
1063-
" --all-properties check and report status of all properties\n"
10641063
" --show-properties show the properties, but don't run analysis\n"
1064+
" --property id only check one specific property\n"
1065+
" --stop-on-fail stop analysis once a failed property is detected\n"
10651066
"\n"
10661067
"C/C++ frontend options:\n"
10671068
" -I path set include path (C/C++)\n"
@@ -1101,6 +1102,7 @@ void cbmc_parse_optionst::help()
11011102
" --round-to-plus-inf rounding towards plus infinity\n"
11021103
" --round-to-minus-inf rounding towards minus infinity\n"
11031104
" --round-to-zero rounding towards zero\n"
1105+
" --function name set main function name\n"
11041106
"\n"
11051107
"Program representations:\n"
11061108
" --show-parse-tree show parse tree\n"
@@ -1130,8 +1132,6 @@ void cbmc_parse_optionst::help()
11301132
" --nondet-static add nondeterministic initialization of variables with static lifetime\n"
11311133
"\n"
11321134
"BMC options:\n"
1133-
" --function name set main function name\n"
1134-
" --property id only check one specific property\n"
11351135
" --program-only only show program expression\n"
11361136
" --show-loops show the loops in the program\n"
11371137
" --depth nr limit search depth\n"

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class optionst;
5353
"(string-abstraction)(no-arch)(arch):" \
5454
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
5555
"(graphml-cex):(json-cex):" \
56-
"(floatbv)(all-claims)(all-properties)(decide)" // legacy, and will eventually disappear
56+
"(floatbv)(all-properties)" // legacy, and will eventually disappear
5757

5858
class cbmc_parse_optionst:
5959
public parse_options_baset,

0 commit comments

Comments
 (0)