Skip to content

Commit 65ba613

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#324 from peterschrammel/refactor-graphml-witnesses
Refactor graphml witnesses
2 parents ab1b944 + 9bf1e35 commit 65ba613

File tree

11 files changed

+407
-136
lines changed

11 files changed

+407
-136
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
extern int __VERIFIER_nondet_int(void);
2+
3+
typedef enum {
4+
LIST_BEG,
5+
LIST_END
6+
} end_point_t;
7+
8+
typedef enum {
9+
ITEM_PREV,
10+
ITEM_NEXT
11+
} direction_t;
12+
13+
void remove_one(end_point_t from)
14+
{
15+
const direction_t next_field = (LIST_BEG == from) ? ITEM_NEXT : ITEM_PREV;
16+
}
17+
18+
end_point_t rand_end_point(void)
19+
{
20+
_Bool choice;
21+
if (choice)
22+
return LIST_BEG;
23+
else
24+
return LIST_END;
25+
}
26+
27+
int main()
28+
{
29+
remove_one(rand_end_point());
30+
31+
__CPROVER_assert(0, "");
32+
33+
return 0;
34+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
CORE
2+
main.c
3+
--graphml-witness -
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
8+
<key attr.name="invariant" attr.type="string" for="node" id="invariant"/>
9+
<key attr.name="invariant.scope" attr.type="string" for="node" id="invariant.scope"/>
10+
<key attr.name="nodeType" attr.type="string" for="node" id="nodetype">
11+
<default>path</default>
12+
</key>
13+
<key attr.name="isFrontierNode" attr.type="boolean" for="node" id="frontier">
14+
<default>false</default>
15+
</key>
16+
<key attr.name="isViolationNode" attr.type="boolean" for="node" id="violation">
17+
<default>false</default>
18+
</key>
19+
<key attr.name="isEntryNode" attr.type="boolean" for="node" id="entry">
20+
<default>false</default>
21+
</key>
22+
<key attr.name="isSinkNode" attr.type="boolean" for="node" id="sink">
23+
<default>false</default>
24+
</key>
25+
<key attr.name="enterLoopHead" attr.type="boolean" for="edge" id="enterLoopHead">
26+
<default>false</default>
27+
</key>
28+
<key attr.name="threadNumber" attr.type="int" for="node" id="thread">
29+
<default>0</default>
30+
</key>
31+
<key attr.name="sourcecodeLanguage" attr.type="string" for="graph" id="sourcecodelang"/>
32+
<key attr.name="programFile" attr.type="string" for="graph" id="programfile"/>
33+
<key attr.name="programHash" attr.type="string" for="graph" id="programhash"/>
34+
<key attr.name="specification" attr.type="string" for="graph" id="specification"/>
35+
<key attr.name="architecture" attr.type="string" for="graph" id="architecture"/>
36+
<key attr.name="producer" attr.type="string" for="graph" id="producer"/>
37+
<key attr.name="sourcecode" attr.type="string" for="edge" id="sourcecode"/>
38+
<key attr.name="startline" attr.type="int" for="edge" id="startline"/>
39+
<key attr.name="control" attr.type="string" for="edge" id="control"/>
40+
<key attr.name="assumption" attr.type="string" for="edge" id="assumption"/>
41+
<key attr.name="assumption.resultfunction" attr.type="string" for="edge" id="assumption.resultfunction"/>
42+
<key attr.name="assumption.scope" attr.type="string" for="edge" id="assumption.scope"/>
43+
<key attr.name="enterFunction" attr.type="string" for="edge" id="enterFunction"/>
44+
<key attr.name="returnFromFunction" attr.type="string" for="edge" id="returnFrom"/>
45+
<key attr.name="witness-type" attr.type="string" for="graph" id="witness-type"/>
46+
<graph edgedefault="directed">
47+
<data key="sourcecodelang">C</data>
48+
<node id="sink"/>
49+
<node id="33.22">
50+
<data key="entry">true</data>
51+
</node>
52+
<edge source="33.22" target="4.29">
53+
<data key="originfile">main.c</data>
54+
<data key="startline">21</data>
55+
</edge>
56+
<node id="4.29"/>
57+
<edge source="4.29" target="29.31">
58+
<data key="originfile">main.c</data>
59+
<data key="startline">29</data>
60+
<data key="assumption.scope">main</data>
61+
</edge>
62+
<node id="29.31"/>
63+
<edge source="29.31" target="5.33">
64+
<data key="originfile">main.c</data>
65+
<data key="startline">15</data>
66+
<data key="assumption.scope">remove_one</data>
67+
</edge>
68+
<node id="5.33">
69+
<data key="violation">true</data>
70+
</node>
71+
<edge source="5.33" target="sink">
72+
<data key="originfile">main.c</data>
73+
<data key="startline">31</data>
74+
</edge>
75+
</graph>
76+
</graphml>
77+
--
78+
^warning: ignoring

src/cbmc/bmc.cpp

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Author: Daniel Kroening, [email protected]
2525

2626
#include <goto-programs/xml_goto_trace.h>
2727
#include <goto-programs/json_goto_trace.h>
28-
#include <goto-programs/graphml_goto_trace.h>
28+
#include <goto-programs/graphml_witness.h>
2929

3030
#include <goto-symex/build_goto_trace.h>
3131
#include <goto-symex/slice.h>
@@ -106,20 +106,40 @@ void bmct::error_trace()
106106
}
107107
break;
108108
}
109+
}
109110

110-
const std::string graphml=options.get_option("graphml-cex");
111-
if(!graphml.empty())
112-
{
113-
graphmlt cex_graph;
114-
convert(ns, goto_trace, cex_graph);
111+
/*******************************************************************\
115112
116-
if(graphml=="-")
117-
write_graphml(cex_graph, std::cout);
118-
else
119-
{
120-
std::ofstream out(graphml);
121-
write_graphml(cex_graph, out);
122-
}
113+
Function: bmct::output_graphml
114+
115+
Inputs:
116+
117+
Outputs:
118+
119+
Purpose: outputs witnesses in graphml format
120+
121+
\*******************************************************************/
122+
123+
void bmct::output_graphml(
124+
resultt result,
125+
const goto_functionst &goto_functions)
126+
{
127+
const std::string graphml=options.get_option("graphml-witness");
128+
if(graphml.empty())
129+
return;
130+
131+
graphml_witnesst graphml_witness(ns);
132+
if(result==UNSAFE)
133+
graphml_witness(safety_checkert::error_trace);
134+
else
135+
return;
136+
137+
if(graphml=="-")
138+
write_graphml(graphml_witness.graph(), std::cout);
139+
else
140+
{
141+
std::ofstream out(graphml);
142+
write_graphml(graphml_witness.graph(), out);
123143
}
124144
}
125145

@@ -294,79 +314,77 @@ void bmct::show_program()
294314

295315
std::cout << "\n" << "Program constraints:" << "\n";
296316

297-
for(symex_target_equationt::SSA_stepst::const_iterator
298-
it=equation.SSA_steps.begin();
299-
it!=equation.SSA_steps.end(); it++)
317+
for(const auto &step : equation.SSA_steps)
300318
{
301-
std::cout << "// " << it->source.pc->location_number << " ";
302-
std::cout << it->source.pc->source_location.as_string() << "\n";
319+
std::cout << "// " << step.source.pc->location_number << " ";
320+
std::cout << step.source.pc->source_location.as_string() << "\n";
303321

304-
if(it->is_assignment())
322+
if(step.is_assignment())
305323
{
306324
std::string string_value;
307-
languages.from_expr(it->cond_expr, string_value);
325+
languages.from_expr(step.cond_expr, string_value);
308326
std::cout << "(" << count << ") " << string_value << "\n";
309327

310-
if(!it->guard.is_true())
328+
if(!step.guard.is_true())
311329
{
312-
languages.from_expr(it->guard, string_value);
330+
languages.from_expr(step.guard, string_value);
313331
std::cout << std::string(i2string(count).size()+3, ' ');
314332
std::cout << "guard: " << string_value << "\n";
315333
}
316334

317335
count++;
318336
}
319-
else if(it->is_assert())
337+
else if(step.is_assert())
320338
{
321339
std::string string_value;
322-
languages.from_expr(it->cond_expr, string_value);
340+
languages.from_expr(step.cond_expr, string_value);
323341
std::cout << "(" << count << ") ASSERT("
324342
<< string_value <<") " << "\n";
325343

326-
if(!it->guard.is_true())
344+
if(!step.guard.is_true())
327345
{
328-
languages.from_expr(it->guard, string_value);
346+
languages.from_expr(step.guard, string_value);
329347
std::cout << std::string(i2string(count).size()+3, ' ');
330348
std::cout << "guard: " << string_value << "\n";
331349
}
332350

333351
count++;
334352
}
335-
else if(it->is_assume())
353+
else if(step.is_assume())
336354
{
337355
std::string string_value;
338-
languages.from_expr(it->cond_expr, string_value);
356+
languages.from_expr(step.cond_expr, string_value);
339357
std::cout << "(" << count << ") ASSUME("
340358
<< string_value <<") " << "\n";
341359

342-
if(!it->guard.is_true())
360+
if(!step.guard.is_true())
343361
{
344-
languages.from_expr(it->guard, string_value);
362+
languages.from_expr(step.guard, string_value);
345363
std::cout << std::string(i2string(count).size()+3, ' ');
346364
std::cout << "guard: " << string_value << "\n";
347365
}
348366

349367
count++;
350368
}
351-
else if(it->is_constraint())
369+
else if(step.is_constraint())
352370
{
353371
std::string string_value;
354-
languages.from_expr(it->cond_expr, string_value);
372+
languages.from_expr(step.cond_expr, string_value);
355373
std::cout << "(" << count << ") CONSTRAINT("
356374
<< string_value <<") " << "\n";
357375

358376
count++;
359377
}
360-
else if(it->is_shared_read() || it->is_shared_write())
378+
else if(step.is_shared_read() || step.is_shared_write())
361379
{
362380
std::string string_value;
363-
languages.from_expr(it->ssa_lhs, string_value);
364-
std::cout << "(" << count << ") SHARED_" << (it->is_shared_write()?"WRITE":"READ") << "("
381+
languages.from_expr(step.ssa_lhs, string_value);
382+
std::cout << "(" << count << ") SHARED_" << (step.is_shared_write()?"WRITE":"READ") << "("
365383
<< string_value <<") " << "\n";
366384

367-
if(!it->guard.is_true())
385+
if(!step.guard.is_true())
368386
{
369-
languages.from_expr(it->guard, string_value);
387+
languages.from_expr(step.guard, string_value);
370388
std::cout << std::string(i2string(count).size()+3, ' ');
371389
std::cout << "guard: " << string_value << "\n";
372390
}
@@ -611,6 +629,7 @@ safety_checkert::resultt bmct::stop_on_fail(
611629
dynamic_cast<bv_cbmct &>(prop_conv), equation, ns);
612630

613631
error_trace();
632+
output_graphml(UNSAFE, goto_functions);
614633
}
615634

616635
report_failure();

src/cbmc/bmc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class bmct:public safety_checkert
103103
virtual void report_failure();
104104

105105
virtual void error_trace();
106-
106+
void output_graphml(
107+
resultt result,
108+
const goto_functionst &goto_functions);
109+
107110
bool cover(
108111
const goto_functionst &goto_functions,
109112
const optionst::value_listt &criteria);

src/cbmc/cbmc_parse_options.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,12 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
454454
if(cmdline.isset("outfile"))
455455
options.set_option("outfile", cmdline.get_value("outfile"));
456456

457-
if(cmdline.isset("graphml-cex"))
458-
options.set_option("graphml-cex", cmdline.get_value("graphml-cex"));
457+
if(cmdline.isset("graphml-witness"))
458+
{
459+
options.set_option("graphml-witness", cmdline.get_value("graphml-witness"));
460+
options.set_option("stop-on-fail", true);
461+
options.set_option("trace", true);
462+
}
459463
}
460464

461465
/*******************************************************************\
@@ -1170,7 +1174,7 @@ void cbmc_parse_optionst::help()
11701174
" --unwinding-assertions generate unwinding assertions\n"
11711175
" --partial-loops permit paths with partial loops\n"
11721176
" --no-pretty-names do not simplify identifiers\n"
1173-
" --graphml-cex filename write the counterexample in GraphML format to filename\n"
1177+
" --graphml-witness filename write the witness in GraphML format to filename\n"
11741178
"\n"
11751179
"Backend options:\n"
11761180
" --dimacs generate CNF in DIMACS format\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
"(arrays-uf-always)(arrays-uf-never)" \
5454
"(string-abstraction)(no-arch)(arch):" \
5555
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
56-
"(graphml-cex):" \
56+
"(graphml-witness):" \
5757
"(localize-faults)(localize-faults-method):" \
5858
"(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear
5959

src/goto-programs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SRC = goto_convert.cpp goto_convert_function_call.cpp \
1515
compute_called_functions.cpp link_to_library.cpp \
1616
remove_returns.cpp osx_fat_reader.cpp remove_complex.cpp \
1717
goto_trace.cpp xml_goto_trace.cpp vcd_goto_trace.cpp \
18-
graphml_goto_trace.cpp remove_virtual_functions.cpp \
18+
graphml_witness.cpp remove_virtual_functions.cpp \
1919
class_hierarchy.cpp show_goto_functions.cpp get_goto_model.cpp
2020

2121
INCLUDES= -I ..

src/goto-programs/graphml_goto_trace.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)