@@ -106,13 +106,6 @@ void remove_returnst::replace_returns(
106
106
// add return_value symbol to symbol_table, if not already created:
107
107
const auto return_symbol = get_or_create_return_value_symbol (function_id);
108
108
109
- // look up the function symbol
110
- symbolt &function_symbol = *symbol_table.get_writeable (function_id);
111
-
112
- // make the return type 'void'
113
- function.type .return_type () = empty_typet ();
114
- function_symbol.type = function.type ;
115
-
116
109
goto_programt &goto_program = function.body ;
117
110
118
111
Forall_goto_program_instructions (i_it, goto_program)
@@ -160,67 +153,50 @@ void remove_returnst::do_function_calls(
160
153
const irep_idt function_id =
161
154
to_symbol_expr (function_call.function ()).get_identifier ();
162
155
163
- optionalt<symbol_exprt> return_value;
164
- typet old_return_type;
165
- bool is_stub = function_is_stub (function_id);
166
-
167
- if (is_stub)
168
- {
169
- old_return_type =
170
- to_code_type (function_call.function ().type ()).return_type ();
171
- }
172
- else
173
- {
174
- // The callee may or may not already have been transformed by this pass,
175
- // so its symbol-table entry may already have void return type.
176
- // To simplify matters, create its return-value global now (if not
177
- // already done), and use that to determine its true return type.
178
- return_value = get_or_create_return_value_symbol (function_id);
179
- if (!return_value.has_value ()) // really void-typed?
180
- continue ;
181
- old_return_type = return_value->type ();
182
- }
183
-
184
156
// Do we return anything?
185
- if (old_return_type != empty_typet ())
157
+ if (
158
+ to_code_type (function_call.function ().type ()).return_type () !=
159
+ empty_typet () &&
160
+ function_call.lhs ().is_not_nil ())
186
161
{
187
162
// replace "lhs=f(...)" by
188
163
// "f(...); lhs=f#return_value; DEAD f#return_value;"
189
164
190
- // fix the type
191
- to_code_type (function_call.function ().type ()).return_type ()=
192
- empty_typet ();
165
+ exprt rhs;
166
+
167
+ bool is_stub = function_is_stub (function_id);
168
+ optionalt<symbol_exprt> return_value;
169
+
170
+ if (!is_stub)
171
+ {
172
+ return_value = get_or_create_return_value_symbol (function_id);
173
+ CHECK_RETURN (return_value.has_value ());
174
+
175
+ // The return type in the definition of the function may differ
176
+ // from the return type in the declaration. We therefore do a
177
+ // cast.
178
+ rhs = typecast_exprt::conditional_cast (
179
+ *return_value, function_call.lhs ().type ());
180
+ }
181
+ else
182
+ {
183
+ rhs = side_effect_expr_nondett (
184
+ function_call.lhs ().type (), i_it->source_location );
185
+ }
186
+
187
+ goto_programt::targett t_a = goto_program.insert_after (
188
+ i_it,
189
+ goto_programt::make_assignment (
190
+ code_assignt (function_call.lhs (), rhs), i_it->source_location ));
191
+
192
+ // fry the previous assignment
193
+ function_call.lhs ().make_nil ();
193
194
194
- if (function_call. lhs (). is_not_nil () )
195
+ if (!is_stub )
195
196
{
196
- exprt rhs;
197
-
198
- if (!is_stub)
199
- {
200
- // The return type in the definition of the function may differ
201
- // from the return type in the declaration. We therefore do a
202
- // cast.
203
- rhs = typecast_exprt::conditional_cast (
204
- *return_value, function_call.lhs ().type ());
205
- }
206
- else
207
- rhs = side_effect_expr_nondett (
208
- function_call.lhs ().type (), i_it->source_location );
209
-
210
- goto_programt::targett t_a = goto_program.insert_after (
211
- i_it,
212
- goto_programt::make_assignment (
213
- code_assignt (function_call.lhs (), rhs), i_it->source_location ));
214
-
215
- // fry the previous assignment
216
- function_call.lhs ().make_nil ();
217
-
218
- if (!is_stub)
219
- {
220
- goto_program.insert_after (
221
- t_a,
222
- goto_programt::make_dead (*return_value, i_it->source_location ));
223
- }
197
+ goto_program.insert_after (
198
+ t_a,
199
+ goto_programt::make_dead (*return_value, i_it->source_location ));
224
200
}
225
201
226
202
// update the call
@@ -299,31 +275,6 @@ void remove_returns(goto_modelt &goto_model)
299
275
rr (goto_model.goto_functions );
300
276
}
301
277
302
- // / Get code type of a function that has had remove_returns run upon it
303
- // / \param symbol_table: global symbol table
304
- // / \param function_id: function to get the type of
305
- // / \return the function's type with its `return_type()` restored to its
306
- // / original value
307
- code_typet original_return_type (
308
- const symbol_table_baset &symbol_table,
309
- const irep_idt &function_id)
310
- {
311
- // look up the function symbol
312
- const symbolt &function_symbol = symbol_table.lookup_ref (function_id);
313
- code_typet type = to_code_type (function_symbol.type );
314
-
315
- // do we have X#return_value?
316
- std::string rv_name=id2string (function_id)+RETURN_VALUE_SUFFIX;
317
-
318
- symbol_tablet::symbolst::const_iterator rv_it=
319
- symbol_table.symbols .find (rv_name);
320
-
321
- if (rv_it != symbol_table.symbols .end ())
322
- type.return_type () = rv_it->second .type ;
323
-
324
- return type;
325
- }
326
-
327
278
// / turns an assignment to fkt#return_value back into 'return x'
328
279
bool remove_returnst::restore_returns (
329
280
goto_functionst::function_mapt::iterator f_it)
@@ -339,13 +290,6 @@ bool remove_returnst::restore_returns(
339
290
if (rv_it==symbol_table.symbols .end ())
340
291
return true ;
341
292
342
- // look up the function symbol
343
- symbolt &function_symbol=*symbol_table.get_writeable (function_id);
344
-
345
- // restore the return type
346
- f_it->second .type =original_return_type (symbol_table, function_id);
347
- function_symbol.type =f_it->second .type ;
348
-
349
293
// remove the return_value symbol from the symbol_table
350
294
irep_idt rv_name_id=rv_it->second .name ;
351
295
symbol_table.erase (rv_it);
@@ -397,12 +341,6 @@ void remove_returnst::undo_function_calls(
397
341
const irep_idt function_id=
398
342
to_symbol_expr (function_call.function ()).get_identifier ();
399
343
400
- const symbolt &function_symbol=ns.lookup (function_id);
401
-
402
- // fix the type
403
- to_code_type (function_call.function ().type ()).return_type ()=
404
- to_code_type (function_symbol.type ).return_type ();
405
-
406
344
// find "f(...); lhs=f#return_value; DEAD f#return_value;"
407
345
// and revert to "lhs=f(...);"
408
346
goto_programt::instructionst::iterator next = std::next (i_it);
0 commit comments