From 4447be00ef68af8de0980080cf1d2bae6ca988e1 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 16 May 2018 10:14:57 +0100 Subject: [PATCH] Fix uninitialised collect_callsites field in call_grapht This only affected people using both collect_callsites and a call graph restricted to those functions reachable from a particular root function, hence slipping through the net. --- src/analyses/call_graph.cpp | 3 ++- unit/analyses/call_graph.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/analyses/call_graph.cpp b/src/analyses/call_graph.cpp index 84b5b91d2cb..881348279f2 100644 --- a/src/analyses/call_graph.cpp +++ b/src/analyses/call_graph.cpp @@ -74,7 +74,8 @@ static void forall_callsites( call_grapht::call_grapht( const goto_functionst &goto_functions, const irep_idt &root, - bool collect_callsites) + bool collect_callsites): + collect_callsites(collect_callsites) { std::stack> pending_stack; pending_stack.push(root); diff --git a/unit/analyses/call_graph.cpp b/unit/analyses/call_graph.cpp index 77e06e7d6ef..ffefc5d93f6 100644 --- a/unit/analyses/call_graph.cpp +++ b/unit/analyses/call_graph.cpp @@ -164,6 +164,28 @@ SCENARIO("call_graph", } } + WHEN("A call graph is constructed from a root and callsite tracking is on") + { + call_grapht call_graph_with_specific_root = + call_grapht::create_from_root_function(goto_model, "B", true); + + THEN("The graph should contain nodes for only B, C and D") + { + call_grapht::nodest correct_value {"B", "C", "D"}; + REQUIRE(call_graph_with_specific_root.nodes == correct_value); + } + THEN("Only B -> C and B -> D edges should exist, each with one callsite") + { + const auto &check_callsites=call_graph_with_specific_root.callsites; + call_grapht::edgest correct_value { {"B", "C"}, {"B", "D"} }; + REQUIRE(call_graph_with_specific_root.edges == correct_value); + for(const auto &edge : call_graph_with_specific_root.edges) + { + REQUIRE(check_callsites.at(edge).size()==1); + } + } + } + WHEN("A call-graph is constructed rooted at B") { call_grapht call_graph_from_b =