Skip to content

Commit 6fa1fdc

Browse files
committed
Do not add unreachable instructions during goto conversion
1 parent cb90b89 commit 6fa1fdc

File tree

3 files changed

+11
-61
lines changed

3 files changed

+11
-61
lines changed

src/goto-programs/goto_convert.cpp

+6-46
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,6 @@ void goto_convertt::convert(
419419
const codet &code,
420420
goto_programt &dest)
421421
{
422-
std::size_t old_tmp_symbols_size=tmp_symbols.size();
423-
424422
const irep_idt &statement=code.get_statement();
425423

426424
if(statement==ID_block)
@@ -542,19 +540,6 @@ void goto_convertt::convert(
542540
else
543541
copy(code, OTHER, dest);
544542

545-
// We only need to kill the temporaries if control
546-
// can get to the end of the block.
547-
#if 0
548-
if(!dest.empty() &&
549-
dest.instructions.back().is_goto() &&
550-
dest.instructions.back().guard.is_true())
551-
tmp_symbols.resize(old_tmp_symbols_size);
552-
else
553-
kill_tmp_symbols(old_tmp_symbols_size, dest);
554-
#else
555-
kill_tmp_symbols(old_tmp_symbols_size, dest);
556-
#endif
557-
558543
// make sure dest is never empty
559544
if(dest.instructions.empty())
560545
{
@@ -566,31 +551,6 @@ void goto_convertt::convert(
566551

567552
/*******************************************************************\
568553
569-
Function: goto_convertt::kill_tmp_symbols
570-
571-
Inputs:
572-
573-
Outputs:
574-
575-
Purpose:
576-
577-
\*******************************************************************/
578-
579-
void goto_convertt::kill_tmp_symbols(
580-
std::size_t final_size,
581-
goto_programt &dest)
582-
{
583-
while(tmp_symbols.size()>final_size)
584-
{
585-
symbol_exprt symbol=tmp_symbols.back();
586-
tmp_symbols.pop_back();
587-
dest.add_instruction(DEAD);
588-
dest.instructions.back().code=code_deadt(symbol);
589-
}
590-
}
591-
592-
/*******************************************************************\
593-
594554
Function: goto_convertt::convert_block
595555
596556
Inputs:
@@ -617,7 +577,8 @@ void goto_convertt::convert_block(
617577
convert(b_code, dest);
618578
}
619579

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

2567-
tmp_symbols.push_back(symbol_ptr->symbol_expr());
2568-
2569-
goto_programt::targett t=dest.add_instruction(DECL);
2570-
t->code=code_declt(symbol_ptr->symbol_expr());
2571-
t->source_location=source_location;
2528+
code_declt decl;
2529+
decl.symbol()=symbol_ptr->symbol_expr();
2530+
decl.add_source_location()=source_location;
2531+
convert_decl(decl, dest);
25722532

25732533
return *symbol_ptr;
25742534
}

src/goto-programs/goto_convert_class.h

-5
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ class goto_convertt:public message_streamt
6363
symbol_exprt make_compound_literal(
6464
const exprt &expr,
6565
goto_programt &dest);
66-
67-
typedef std::list<symbol_exprt> tmp_symbolst;
68-
tmp_symbolst tmp_symbols;
6966

7067
//
7168
// translation of C expressions (with side effects)
@@ -87,8 +84,6 @@ class goto_convertt:public message_streamt
8784
exprt &expr,
8885
const std::string &suffix,
8986
goto_programt &);
90-
91-
void kill_tmp_symbols(std::size_t, goto_programt &);
9287

9388
void rewrite_boolean(exprt &dest);
9489

src/goto-programs/goto_convert_side_effect.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ void goto_convertt::remove_function_call(
417417

418418
new_name(new_symbol);
419419

420-
tmp_symbols.push_back(new_symbol.symbol_expr());
421-
422420
{
423421
code_declt decl;
424422
decl.symbol()=new_symbol.symbol_expr();
@@ -488,7 +486,11 @@ void goto_convertt::remove_cpp_new(
488486
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);
489487

490488
new_name(new_symbol);
491-
tmp_symbols.push_back(new_symbol.symbol_expr());
489+
490+
code_declt decl;
491+
decl.symbol()=new_symbol.symbol_expr();
492+
decl.add_source_location()=new_symbol.location;
493+
convert_decl(decl, dest);
492494

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

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

562564
new_name(new_symbol);
563-
tmp_symbols.push_back(new_symbol.symbol_expr());
564565

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

705706
{
706-
// this likely needs to be a proper stack
707-
tmp_symbolst old_tmp_symbols;
708-
old_tmp_symbols.swap(tmp_symbols);
709-
710707
goto_programt tmp;
711708
convert(code, tmp);
712709
dest.destructive_append(tmp);
713-
714-
old_tmp_symbols.swap(tmp_symbols);
715710
}
716711

717712
static_cast<exprt &>(expr)=tmp_symbol_expr;

0 commit comments

Comments
 (0)