Skip to content

Commit 410b5e8

Browse files
author
thk123
committed
Create an instruction for assigning the stub return to a variable
Previuosly we were returning the NONDET expression directly. However, we were creating a symbol which was then not being used. This symbol's name was then being used in the interpreter to work out what the function should return. This mirrors how the java test generation handles stubbing, but I think we could probably do without this temporary variable as there is the standard function_name#return_value variable.
1 parent 0f4b854 commit 410b5e8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ansi-c/ansi_c_language.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,29 @@ irep_idt ansi_c_languaget::generate_opaque_stub_body(
9494

9595
if(return_type.id()!=ID_nil)
9696
{
97+
// Build an auxillary symbol to store the return value for
98+
// this function
9799
auxiliary_symbolt return_symbol;
98100
return_symbol.name=get_stub_return_symbol_name(symbol.name);
99101
return_symbol.base_name=return_symbol.name;
100102
return_symbol.mode=ID_C;
101103
return_symbol.type=return_type;
102104

105+
// Put this symbol into the symbol table
103106
symbolt *symbol_ptr=nullptr;
104107
symbol_table.move(return_symbol, symbol_ptr);
105108
assert(symbol_ptr);
106109

110+
// Assign a NONDET expression to the temporary symbol
111+
symbol_exprt temp_return_symbol(symbol_ptr->name, return_type);
107112
exprt return_symbol_expr=side_effect_expr_nondett(return_type);
108-
new_instructions.copy_to_operands(code_returnt(return_symbol_expr));
113+
code_declt temp_return_decl(temp_return_symbol);
114+
temp_return_decl.copy_to_operands(return_symbol_expr);
115+
116+
// Add the temporary symbol declaration and the return expression
117+
// to the body for the stubbed function
118+
new_instructions.copy_to_operands(temp_return_decl);
119+
new_instructions.copy_to_operands(code_returnt(temp_return_symbol));
109120
symbol.value=new_instructions;
110121
return symbol_ptr->name;
111122
}

0 commit comments

Comments
 (0)