Skip to content

Do not generate necessarily dead instructions #73

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
merged 2 commits into from
May 30, 2016
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
12 changes: 1 addition & 11 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ static void unreachable_instructions(
it!=dominators.cfg.entry_map.end();
++it)
{
if(it->first->is_dead() ||
(it->first->is_assign() &&
to_code_assign(it->first->code).lhs().get(ID_identifier)==
"__CPROVER_dead_object"))
continue;

const cfg_dominatorst::cfgt::nodet &n=dominators.cfg[it->second];
if(n.dominators.empty())
dest.insert(std::make_pair(it->first->location_number,
Expand All @@ -78,11 +72,7 @@ static void all_unreachable(
dead_mapt &dest)
{
forall_goto_program_instructions(it, goto_program)
if(!it->is_end_function() &&
!it->is_dead() &&
!(it->is_assign() &&
to_code_assign(it->code).lhs().get(ID_identifier)==
"__CPROVER_dead_object"))
if(!it->is_end_function())
dest.insert(std::make_pair(it->location_number, it));
}

Expand Down
52 changes: 6 additions & 46 deletions src/goto-programs/goto_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ void goto_convertt::convert(
const codet &code,
goto_programt &dest)
{
std::size_t old_tmp_symbols_size=tmp_symbols.size();

const irep_idt &statement=code.get_statement();

if(statement==ID_block)
Expand Down Expand Up @@ -542,19 +540,6 @@ void goto_convertt::convert(
else
copy(code, OTHER, dest);

// We only need to kill the temporaries if control
// can get to the end of the block.
#if 0
if(!dest.empty() &&
dest.instructions.back().is_goto() &&
dest.instructions.back().guard.is_true())
tmp_symbols.resize(old_tmp_symbols_size);
else
kill_tmp_symbols(old_tmp_symbols_size, dest);
#else
kill_tmp_symbols(old_tmp_symbols_size, dest);
#endif

// make sure dest is never empty
if(dest.instructions.empty())
{
Expand All @@ -566,31 +551,6 @@ void goto_convertt::convert(

/*******************************************************************\

Function: goto_convertt::kill_tmp_symbols

Inputs:

Outputs:

Purpose:

\*******************************************************************/

void goto_convertt::kill_tmp_symbols(
std::size_t final_size,
goto_programt &dest)
{
while(tmp_symbols.size()>final_size)
{
symbol_exprt symbol=tmp_symbols.back();
tmp_symbols.pop_back();
dest.add_instruction(DEAD);
dest.instructions.back().code=code_deadt(symbol);
}
}

/*******************************************************************\

Function: goto_convertt::convert_block

Inputs:
Expand All @@ -617,7 +577,8 @@ void goto_convertt::convert_block(
convert(b_code, dest);
}

// see if we need to do any destructors
// see if we need to do any destructors -- may have been processed
// in a prior break/continue/return already, don't create dead code
if(!dest.empty() &&
dest.instructions.back().is_goto() &&
dest.instructions.back().guard.is_true())
Expand Down Expand Up @@ -2564,11 +2525,10 @@ symbolt &goto_convertt::new_tmp_symbol(
new_symbol.location=source_location;
} while(symbol_table.move(new_symbol, symbol_ptr));

tmp_symbols.push_back(symbol_ptr->symbol_expr());

goto_programt::targett t=dest.add_instruction(DECL);
t->code=code_declt(symbol_ptr->symbol_expr());
t->source_location=source_location;
code_declt decl;
decl.symbol()=symbol_ptr->symbol_expr();
decl.add_source_location()=source_location;
convert_decl(decl, dest);

return *symbol_ptr;
}
Expand Down
5 changes: 0 additions & 5 deletions src/goto-programs/goto_convert_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class goto_convertt:public message_streamt
symbol_exprt make_compound_literal(
const exprt &expr,
goto_programt &dest);

typedef std::list<symbol_exprt> tmp_symbolst;
tmp_symbolst tmp_symbols;

//
// translation of C expressions (with side effects)
Expand All @@ -87,8 +84,6 @@ class goto_convertt:public message_streamt
exprt &expr,
const std::string &suffix,
goto_programt &);

void kill_tmp_symbols(std::size_t, goto_programt &);

void rewrite_boolean(exprt &dest);

Expand Down
15 changes: 5 additions & 10 deletions src/goto-programs/goto_convert_side_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,6 @@ void goto_convertt::remove_function_call(

new_name(new_symbol);

tmp_symbols.push_back(new_symbol.symbol_expr());

{
code_declt decl;
decl.symbol()=new_symbol.symbol_expr();
Expand Down Expand Up @@ -488,7 +486,11 @@ void goto_convertt::remove_cpp_new(
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);

new_name(new_symbol);
tmp_symbols.push_back(new_symbol.symbol_expr());

code_declt decl;
decl.symbol()=new_symbol.symbol_expr();
decl.add_source_location()=new_symbol.location;
convert_decl(decl, dest);

call=code_assignt(new_symbol.symbol_expr(), expr);

Expand Down Expand Up @@ -560,7 +562,6 @@ void goto_convertt::remove_malloc(
new_symbol.location=expr.source_location();

new_name(new_symbol);
tmp_symbols.push_back(new_symbol.symbol_expr());

code_declt decl;
decl.symbol()=new_symbol.symbol_expr();
Expand Down Expand Up @@ -703,15 +704,9 @@ void goto_convertt::remove_statement_expression(
id2string(last.get(ID_statement))+"'";

{
// this likely needs to be a proper stack
tmp_symbolst old_tmp_symbols;
old_tmp_symbols.swap(tmp_symbols);

goto_programt tmp;
convert(code, tmp);
dest.destructive_append(tmp);

old_tmp_symbols.swap(tmp_symbols);
}

static_cast<exprt &>(expr)=tmp_symbol_expr;
Expand Down