Skip to content

Commit f752c55

Browse files
author
Daniel Kroening
committed
deal with return values and virtual functions
1 parent d5173af commit f752c55

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

src/path-symex/path_symex.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ void path_symext::function_call_rec(
615615
thread.call_stack.back().current_function=function_identifier;
616616
thread.call_stack.back().return_location=thread.pc.next_loc();
617617
thread.call_stack.back().return_lhs=call.lhs();
618+
thread.call_stack.back().return_rhs=nil_exprt();
618619

619620
#if 0
620621
for(loc_reft l=function_entry_point; ; ++l)
@@ -720,9 +721,7 @@ Function: path_symext::return_from_function
720721
721722
\*******************************************************************/
722723

723-
void path_symext::return_from_function(
724-
path_symex_statet &state,
725-
const exprt &return_value)
724+
void path_symext::return_from_function(path_symex_statet &state)
726725
{
727726
path_symex_statet::threadt &thread=state.threads[state.get_current_thread()];
728727

@@ -740,9 +739,10 @@ void path_symext::return_from_function(
740739
thread.pc=thread.call_stack.back().return_location;
741740

742741
// assign the return value
743-
if(return_value.is_not_nil() &&
742+
if(thread.call_stack.back().return_rhs.is_not_nil() &&
744743
thread.call_stack.back().return_lhs.is_not_nil())
745-
assign(state, thread.call_stack.back().return_lhs, return_value);
744+
assign(state, thread.call_stack.back().return_lhs,
745+
thread.call_stack.back().return_rhs);
746746

747747
// restore the local variables
748748
for(path_symex_statet::var_state_mapt::const_iterator
@@ -758,6 +758,30 @@ void path_symext::return_from_function(
758758

759759
/*******************************************************************\
760760
761+
Function: path_symext::set_return_value
762+
763+
Inputs:
764+
765+
Outputs:
766+
767+
Purpose:
768+
769+
\*******************************************************************/
770+
771+
void path_symext::set_return_value(
772+
path_symex_statet &state,
773+
const exprt &v)
774+
{
775+
path_symex_statet::threadt &thread=
776+
state.threads[state.get_current_thread()];
777+
778+
// returning from very last function?
779+
if(!thread.call_stack.empty())
780+
thread.call_stack.back().return_rhs=v;
781+
}
782+
783+
/*******************************************************************\
784+
761785
Function: path_symext::do_goto
762786
763787
Inputs:
@@ -892,17 +916,16 @@ void path_symext::operator()(
892916
case END_FUNCTION:
893917
// pop the call stack
894918
state.record_step();
895-
return_from_function(state, nil_exprt());
919+
return_from_function(state);
896920
break;
897921

898922
case RETURN:
899-
// pop the call stack
900-
{
901-
state.record_step();
902-
exprt return_val=instruction.code.operands().size()==1?
903-
instruction.code.op0():nil_exprt();
904-
return_from_function(state, return_val);
905-
}
923+
// sets the return value
924+
state.record_step();
925+
926+
if(instruction.code.operands().size()==1)
927+
set_return_value(state, instruction.code.op0());
928+
906929
break;
907930

908931
case START_THREAD:

src/path-symex/path_symex_class.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class path_symext
6161
const exprt &function,
6262
std::list<path_symex_statet> &further_states);
6363

64-
void return_from_function(
65-
path_symex_statet &state,
66-
const exprt &return_value);
64+
void return_from_function(path_symex_statet &state);
65+
66+
void set_return_value(path_symex_statet &, const exprt &);
6767

6868
void symex_malloc(
6969
path_symex_statet &state,

src/path-symex/path_symex_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct path_symex_statet
6969
irep_idt current_function;
7070
loc_reft return_location;
7171
exprt return_lhs;
72+
exprt return_rhs;
7273
var_state_mapt saved_local_vars;
7374
};
7475

src/symex/symex_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Author: Daniel Kroening, [email protected]
3030
#include <goto-programs/goto_inline.h>
3131
#include <goto-programs/xml_goto_trace.h>
3232
#include <goto-programs/remove_complex.h>
33-
#include <goto-programs/remove_returns.h>
3433
#include <goto-programs/remove_vector.h>
34+
#include <goto-programs/remove_virtual_functions.h>
3535

3636
#include <analyses/goto_check.h>
3737

@@ -542,7 +542,7 @@ bool symex_parse_optionst::process_goto_program(
542542
// remove stuff
543543
remove_complex(symbol_table, goto_functions);
544544
remove_vector(symbol_table, goto_functions);
545-
remove_returns(symbol_table, goto_functions);
545+
remove_virtual_functions(symbol_table, goto_functions);
546546

547547
// recalculate numbers, etc.
548548
goto_functions.update();

0 commit comments

Comments
 (0)