@@ -41,8 +41,10 @@ call_grapht::call_grapht(
4141{
4242 forall_goto_functions (f_it, goto_functions)
4343 {
44- const goto_programt &body=f_it->second .body ;
45- add (f_it->first , body);
44+ const irep_idt &function_name = f_it->first ;
45+ const goto_programt &body = f_it->second .body ;
46+ nodes.insert (function_name);
47+ add (function_name, body);
4648 }
4749}
4850
@@ -84,12 +86,14 @@ call_grapht::call_grapht(
8486 const goto_programt &goto_program=
8587 goto_functions.function_map .at (function).body ;
8688
89+ nodes.insert (function);
90+
8791 forall_callsites (
8892 goto_program,
8993 [&](goto_programt::const_targett i_it, const irep_idt &callee)
9094 {
9195 add (function, callee, i_it);
92- if (graph .find (callee)==graph .end ())
96+ if (edges .find (callee)==edges .end ())
9397 pending_stack.push (callee);
9498 }
9599 ); // NOLINT
@@ -129,7 +133,9 @@ void call_grapht::add(
129133 const irep_idt &caller,
130134 const irep_idt &callee)
131135{
132- graph.insert (std::pair<irep_idt, irep_idt>(caller, callee));
136+ edges.insert ({caller, callee});
137+ nodes.insert (caller);
138+ nodes.insert (callee);
133139}
134140
135141// / Add edge with optional callsite information
@@ -152,7 +158,8 @@ void call_grapht::add(
152158call_grapht call_grapht::get_inverted () const
153159{
154160 call_grapht result;
155- for (const auto &caller_callee : graph)
161+ result.nodes = nodes;
162+ for (const auto &caller_callee : edges)
156163 result.add (caller_callee.second , caller_callee.first );
157164 return result;
158165}
@@ -197,7 +204,12 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
197204 call_grapht::directed_grapht ret;
198205 function_indicest function_indices (ret);
199206
200- for (const auto &edge : graph)
207+ // To make sure we include unreachable functions we first create indices
208+ // for all nodes in the graph
209+ for (const irep_idt &function_name : nodes)
210+ function_indices[function_name];
211+
212+ for (const auto &edge : edges)
201213 {
202214 auto a_index=function_indices[edge.first ];
203215 auto b_index=function_indices[edge.second ];
@@ -237,7 +249,7 @@ void call_grapht::output_dot(std::ostream &out) const
237249{
238250 out << " digraph call_graph {\n " ;
239251
240- for (const auto &edge : graph )
252+ for (const auto &edge : edges )
241253 {
242254 out << " \" " << edge.first << " \" -> "
243255 << " \" " << edge.second << " \" "
@@ -252,7 +264,7 @@ void call_grapht::output_dot(std::ostream &out) const
252264
253265void call_grapht::output (std::ostream &out) const
254266{
255- for (const auto &edge : graph )
267+ for (const auto &edge : edges )
256268 {
257269 out << edge.first << " -> " << edge.second << " \n " ;
258270 if (collect_callsites)
@@ -267,7 +279,7 @@ void call_grapht::output_xml(std::ostream &out) const
267279 if (collect_callsites)
268280 out << " <!-- XML call-graph representation does not document callsites yet."
269281 " If you need this, edit call_grapht::output_xml -->\n " ;
270- for (const auto &edge : graph )
282+ for (const auto &edge : edges )
271283 {
272284 out << " <call_graph_edge caller=\" " ;
273285 xmlt::escape_attribute (id2string (edge.first ), out);
0 commit comments