Skip to content

CONTRACTS: Remove helper method check_for_looped_mallocs #6729

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

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
63 changes: 0 additions & 63 deletions src/goto-instrument/contracts/contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,69 +1225,6 @@ goto_functionst &code_contractst::get_goto_functions()
return goto_functions;
}

bool code_contractst::check_for_looped_mallocs(const goto_programt &program)
{
// Collect all GOTOs and mallocs
std::vector<goto_programt::instructiont> back_gotos;
std::vector<goto_programt::instructiont> malloc_calls;

int index = 0;
for(goto_programt::instructiont instruction : program.instructions)
{
if(instruction.is_backwards_goto())
{
back_gotos.push_back(instruction);
}
if(instruction.is_function_call())
{
irep_idt called_name;
if(instruction.call_function().id() == ID_dereference)
{
called_name =
to_symbol_expr(
to_dereference_expr(instruction.call_function()).pointer())
.get_identifier();
}
else
{
called_name =
to_symbol_expr(instruction.call_function()).get_identifier();
}

if(called_name == "malloc")
{
malloc_calls.push_back(instruction);
}
}
index++;
}
// Make sure there are no gotos that go back such that a malloc
// is between the goto and its destination (possible loop).
for(auto goto_entry : back_gotos)
{
for(const auto &target : goto_entry.targets)
{
for(auto malloc_entry : malloc_calls)
{
if(
malloc_entry.location_number >= target->location_number &&
malloc_entry.location_number < goto_entry.location_number)
{
log.error() << "Call to malloc at location "
<< malloc_entry.location_number << " falls between goto "
<< "source location " << goto_entry.location_number
<< " and it's destination at location "
<< target->location_number << ". "
<< "Unable to complete instrumentation, as this malloc "
<< "may be in a loop." << messaget::eom;
throw 0;
}
}
}
}
return false;
}

bool code_contractst::check_frame_conditions_function(const irep_idt &function)
{
// Get the function object before instrumentation.
Expand Down
4 changes: 0 additions & 4 deletions src/goto-instrument/contracts/contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ class code_contractst
/// Instrument functions to check frame conditions.
bool check_frame_conditions_function(const irep_idt &function);

/// Check if there are any malloc statements which may be repeated because of
/// a goto statement that jumps back.
bool check_for_looped_mallocs(const goto_programt &program);

/// Apply loop contracts, whenever available, to all loops in `function`.
/// Loop invariants, loop variants, and loop assigns clauses.
void apply_loop_contract(
Expand Down