Skip to content

Commit 3b88c4f

Browse files
committed
Per function shortest path graph
Builds a CFG for every goto_program in goto_functions, and computes the distance for every location in the CFGs to the property, if one exists in taht CFG, or to the end of the function Writes these numbers to locst passed as argument to the constructor, in order to use numbers to guide symex search
1 parent fc92f17 commit 3b88c4f

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/symex/shortest_path_graph.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,56 @@ Author: [email protected]
99
#include "shortest_path_graph.h"
1010

1111
#include <algorithm>
12+
13+
void shortest_path_grapht::get_path_lengths_in_function()
14+
{
15+
bool found_property = false;
16+
bool found_end = false;
17+
node_indext end_index;
18+
node_indext property_index;
19+
node_indext index = 0;
20+
for(auto &n : nodes)
21+
{
22+
if(n.PC->is_assert())
23+
{
24+
if(found_property == false)
25+
{
26+
n.is_property = true;
27+
n.shortest_path_to_property = 0;
28+
found_property = true;
29+
property_index = index;
30+
}
31+
else
32+
throw "shortest path search cannot be used with multiple properties";
33+
}
34+
if(n.PC->is_end_function())
35+
{
36+
end_index = index;
37+
found_end = true;
38+
}
39+
index++;
40+
}
41+
42+
if(!found_property)
43+
{
44+
nodes[end_index].shortest_path_to_property = 0;
45+
bfs(end_index);
46+
}
47+
else
48+
bfs(property_index);
49+
50+
write_lengths_to_locs();
51+
}
52+
53+
void per_function_shortest_patht::build(const goto_functionst &goto_functions)
54+
{
55+
forall_goto_functions(it, goto_functions)
56+
if(it->second.body_available())
57+
{
58+
shortest_path_grapht path_graph(it->second.body, locs);
59+
}
60+
}
61+
1262
void shortest_path_grapht::bfs(node_indext property_index)
1363
{
1464
// does BFS, not Dijkstra

src/symex/shortest_path_graph.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ class shortest_path_grapht: public cfg_baset<shortest_path_nodet>
4949
get_path_lengths_to_property();
5050
}
5151

52+
explicit shortest_path_grapht(
53+
const goto_programt &_goto_program, locst &_locs):
54+
locs(_locs),
55+
target_to_loc_map(_locs)
56+
{
57+
cfg_baset<shortest_path_nodet>::operator()(_goto_program);
58+
get_path_lengths_in_function();
59+
}
60+
5261
protected:
5362
/// \brief writes the computed shortest path for every node
5463
/// in the graph to the corresponding location in locst.
@@ -60,6 +69,11 @@ class shortest_path_grapht: public cfg_baset<shortest_path_nodet>
6069
/// is present, we use the first one discovered.
6170
/// Calls bfs() to do this.
6271
void get_path_lengths_to_property();
72+
/// \brief computes the shortest path from every node in a
73+
/// graph to the property, or the end of the funciton if
74+
/// there is no property.
75+
/// we assume the graph is a graph of a single function.
76+
void get_path_lengths_in_function();
6377
/// \brief implements backwards BFS to compute distance from every node in
6478
/// the graph to the node index given as parameter
6579
/// \param destination node index
@@ -69,4 +83,27 @@ class shortest_path_grapht: public cfg_baset<shortest_path_nodet>
6983
target_to_loc_mapt target_to_loc_map;
7084
};
7185

86+
/// \brief class contains CFG of program locations
87+
/// for every function with the shortest distance to a
88+
/// property, or the end of a function, calculated for each location
89+
/// The distances computed for each node are written to the corresponding
90+
/// loct in the locst passed as param to the constructor. This allows us
91+
/// to use these numbers to guide a symex search
92+
/// \param goto functions to create the CFGs from, locs struct made from the
93+
/// same goto_functions
94+
class per_function_shortest_patht
95+
{
96+
public:
97+
explicit per_function_shortest_patht(
98+
const goto_functionst &_goto_functions, locst &_locs):
99+
locs(_locs)
100+
{
101+
build(_goto_functions);
102+
}
103+
104+
protected:
105+
locst &locs;
106+
void build(const goto_functionst & goto_functions);
107+
};
108+
72109
#endif /* CPROVER_SYMEX_SHORTEST_PATH_GRAPH_H */

0 commit comments

Comments
 (0)