Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream fpr #2234

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ void unreachable_instructions(
{
json_arrayt json_result;

std::set<irep_idt> called=
compute_called_functions(goto_model);
std::unordered_set<irep_idt> called = compute_called_functions(goto_model);

const namespacet ns(goto_model.symbol_table);

Expand Down Expand Up @@ -291,7 +290,7 @@ static void xml_output_function(

static void list_functions(
const goto_modelt &goto_model,
const std::set<irep_idt> called,
const std::unordered_set<irep_idt> &called,
const optionst &options,
std::ostream &os,
bool unreachable)
Expand Down Expand Up @@ -387,7 +386,7 @@ void unreachable_functions(
else
options.set_option("text", true);

std::set<irep_idt> called = compute_called_functions(goto_model);
std::unordered_set<irep_idt> called = compute_called_functions(goto_model);

list_functions(goto_model, called, options, os, true);
}
Expand All @@ -403,17 +402,16 @@ void reachable_functions(
else
options.set_option("text", true);

std::set<irep_idt> called = compute_called_functions(goto_model);
std::unordered_set<irep_idt> called = compute_called_functions(goto_model);

list_functions(goto_model, called, options, os, false);
}


std::set<irep_idt> compute_called_functions_from_ai(
std::unordered_set<irep_idt> compute_called_functions_from_ai(
const goto_modelt &goto_model,
const ai_baset &ai)
{
std::set<irep_idt> called;
std::unordered_set<irep_idt> called;

forall_goto_functions(f_it, goto_model.goto_functions)
{
Expand All @@ -436,7 +434,8 @@ bool static_unreachable_functions(
message_handlert &message_handler,
std::ostream &out)
{
std::set<irep_idt> called = compute_called_functions_from_ai(goto_model, ai);
std::unordered_set<irep_idt> called =
compute_called_functions_from_ai(goto_model, ai);

list_functions(goto_model, called, options, out, true);

Expand All @@ -450,7 +449,8 @@ bool static_reachable_functions(
message_handlert &message_handler,
std::ostream &out)
{
std::set<irep_idt> called = compute_called_functions_from_ai(goto_model, ai);
std::unordered_set<irep_idt> called =
compute_called_functions_from_ai(goto_model, ai);

list_functions(goto_model, called, options, out, false);

Expand Down
32 changes: 14 additions & 18 deletions src/goto-programs/compute_called_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
/// get all functions whose address is taken
void compute_address_taken_functions(
const exprt &src,
std::set<irep_idt> &address_taken)
std::unordered_set<irep_idt> &address_taken)
{
forall_operands(it, src)
compute_address_taken_functions(*it, address_taken);
Expand All @@ -35,7 +35,7 @@ void compute_address_taken_functions(
/// get all functions in the expression
void compute_functions(
const exprt &src,
std::set<irep_idt> &address_taken)
std::unordered_set<irep_idt> &address_taken)
{
forall_operands(it, src)
compute_functions(*it, address_taken);
Expand All @@ -48,7 +48,7 @@ void compute_functions(
/// get all functions whose address is taken
void compute_address_taken_functions(
const goto_programt &goto_program,
std::set<irep_idt> &address_taken)
std::unordered_set<irep_idt> &address_taken)
{
forall_goto_program_instructions(it, goto_program)
{
Expand All @@ -60,28 +60,27 @@ void compute_address_taken_functions(
/// get all functions whose address is taken
void compute_address_taken_functions(
const goto_functionst &goto_functions,
std::set<irep_idt> &address_taken)
std::unordered_set<irep_idt> &address_taken)
{
forall_goto_functions(it, goto_functions)
compute_address_taken_functions(it->second.body, address_taken);
}

/// get all functions whose address is taken
std::set<irep_idt> compute_address_taken_functions(
const goto_functionst &goto_functions)
std::unordered_set<irep_idt>
compute_address_taken_functions(const goto_functionst &goto_functions)
{
std::set<irep_idt> address_taken;
std::unordered_set<irep_idt> address_taken;
compute_address_taken_functions(goto_functions, address_taken);
return address_taken;
}

/// computes the functions that are (potentially) called
std::set<irep_idt> compute_called_functions(
const goto_functionst &goto_functions)
std::unordered_set<irep_idt>
compute_called_functions(const goto_functionst &goto_functions)
{
std::set<irep_idt> working_queue;
std::set<irep_idt> done;
std::set<irep_idt> functions;
std::unordered_set<irep_idt> working_queue;
std::unordered_set<irep_idt> functions;

// start from entry point
working_queue.insert(goto_functions.entry_point());
Expand All @@ -91,12 +90,9 @@ std::set<irep_idt> compute_called_functions(
irep_idt id=*working_queue.begin();
working_queue.erase(working_queue.begin());

if(done.find(id)!=done.end())
if(!functions.insert(id).second)
continue;

functions.insert(id);
done.insert(id);

const goto_functionst::function_mapt::const_iterator f_it=
goto_functions.function_map.find(id);

Expand All @@ -123,8 +119,8 @@ std::set<irep_idt> compute_called_functions(
}

/// computes the functions that are (potentially) called
std::set<irep_idt> compute_called_functions(
const goto_modelt &goto_model)
std::unordered_set<irep_idt>
compute_called_functions(const goto_modelt &goto_model)
{
return compute_called_functions(goto_model.goto_functions);
}
10 changes: 5 additions & 5 deletions src/goto-programs/compute_called_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ Author: Daniel Kroening, [email protected]

void compute_address_taken_functions(
const exprt &,
std::set<irep_idt> &);
std::unordered_set<irep_idt> &);

void compute_address_taken_functions(
const goto_programt &,
std::set<irep_idt> &);
std::unordered_set<irep_idt> &);

void compute_address_taken_functions(
const goto_functionst &,
std::set<irep_idt> &);
std::unordered_set<irep_idt> &);

// computes the functions that are (potentially) called
std::set<irep_idt> compute_called_functions(const goto_functionst &);
std::set<irep_idt> compute_called_functions(const goto_modelt &);
std::unordered_set<irep_idt> compute_called_functions(const goto_functionst &);
std::unordered_set<irep_idt> compute_called_functions(const goto_modelt &);

#endif // CPROVER_GOTO_PROGRAMS_COMPUTE_CALLED_FUNCTIONS_H
2 changes: 1 addition & 1 deletion src/goto-programs/link_to_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void link_to_library(

while(true)
{
std::set<irep_idt> called_functions=
std::unordered_set<irep_idt> called_functions =
compute_called_functions(goto_functions);

// eliminate those for which we already have a body
Expand Down
6 changes: 3 additions & 3 deletions src/goto-programs/remove_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class remove_function_pointerst:public messaget
goto_programt &goto_program,
goto_programt::targett target);

std::set<irep_idt> address_taken;
std::unordered_set<irep_idt> address_taken;

typedef std::map<irep_idt, code_typet> type_mapt;
type_mapt type_map;
Expand All @@ -80,8 +80,8 @@ class remove_function_pointerst:public messaget
code_function_callt &function_call,
goto_programt &dest);

void compute_address_taken_in_symbols(
std::set<irep_idt> &address_taken)
void
compute_address_taken_in_symbols(std::unordered_set<irep_idt> &address_taken)
{
const symbol_tablet &symbol_table=ns.get_symbol_table();

Expand Down