@@ -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)
@@ -164,73 +157,56 @@ bool remove_returnst::do_function_calls(
164
157
const irep_idt function_id =
165
158
to_symbol_expr (function_call.function ()).get_identifier ();
166
159
167
- optionalt<symbol_exprt> return_value;
168
- typet old_return_type;
169
- bool is_stub = function_is_stub (function_id);
170
-
171
- if (is_stub)
172
- {
173
- old_return_type =
174
- to_code_type (function_call.function ().type ()).return_type ();
175
- }
176
- else
177
- {
178
- // The callee may or may not already have been transformed by this pass,
179
- // so its symbol-table entry may already have void return type.
180
- // To simplify matters, create its return-value global now (if not
181
- // already done), and use that to determine its true return type.
182
- return_value = get_or_create_return_value_symbol (function_id);
183
- if (!return_value.has_value ()) // really void-typed?
184
- continue ;
185
- old_return_type = return_value->type ();
186
- }
187
-
188
160
// Do we return anything?
189
- if (old_return_type != empty_typet ())
161
+ if (
162
+ to_code_type (function_call.function ().type ()).return_type () !=
163
+ empty_typet () &&
164
+ function_call.lhs ().is_not_nil ())
190
165
{
191
166
// replace "lhs=f(...)" by
192
167
// "f(...); lhs=f#return_value; DEAD f#return_value;"
193
168
194
- // fix the type
195
- to_code_type (function_call.function ().type ()).return_type ()=
196
- empty_typet ();
169
+ exprt rhs;
170
+
171
+ bool is_stub = function_is_stub (function_id);
172
+ optionalt<symbol_exprt> return_value;
173
+
174
+ if (!is_stub)
175
+ {
176
+ return_value = get_or_create_return_value_symbol (function_id);
177
+ CHECK_RETURN (return_value.has_value ());
178
+
179
+ // The return type in the definition of the function may differ
180
+ // from the return type in the declaration. We therefore do a
181
+ // cast.
182
+ rhs = typecast_exprt::conditional_cast (
183
+ *return_value, function_call.lhs ().type ());
184
+ }
185
+ else
186
+ {
187
+ rhs = side_effect_expr_nondett (
188
+ function_call.lhs ().type (), i_it->source_location );
189
+ }
190
+
191
+ goto_programt::targett t_a = goto_program.insert_after (
192
+ i_it,
193
+ goto_programt::make_assignment (
194
+ code_assignt (function_call.lhs (), rhs), i_it->source_location ));
195
+
196
+ // fry the previous assignment
197
+ function_call.lhs ().make_nil ();
197
198
198
- if (function_call. lhs (). is_not_nil () )
199
+ if (!is_stub )
199
200
{
200
- exprt rhs;
201
-
202
- if (!is_stub)
203
- {
204
- // The return type in the definition of the function may differ
205
- // from the return type in the declaration. We therefore do a
206
- // cast.
207
- rhs = typecast_exprt::conditional_cast (
208
- *return_value, function_call.lhs ().type ());
209
- }
210
- else
211
- rhs = side_effect_expr_nondett (
212
- function_call.lhs ().type (), i_it->source_location );
213
-
214
- goto_programt::targett t_a = goto_program.insert_after (
215
- i_it,
216
- goto_programt::make_assignment (
217
- code_assignt (function_call.lhs (), rhs), i_it->source_location ));
218
-
219
- // fry the previous assignment
220
- function_call.lhs ().make_nil ();
221
-
222
- if (!is_stub)
223
- {
224
- goto_program.insert_after (
225
- t_a,
226
- goto_programt::make_dead (*return_value, i_it->source_location ));
227
- }
228
-
229
- requires_update = true ;
201
+ goto_program.insert_after (
202
+ t_a,
203
+ goto_programt::make_dead (*return_value, i_it->source_location ));
230
204
}
231
205
232
206
// update the call
233
207
i_it->set_function_call (function_call);
208
+
209
+ requires_update = true ;
234
210
}
235
211
}
236
212
}
@@ -309,31 +285,6 @@ void remove_returns(goto_modelt &goto_model)
309
285
rr (goto_model.goto_functions );
310
286
}
311
287
312
- // / Get code type of a function that has had remove_returns run upon it
313
- // / \param symbol_table: global symbol table
314
- // / \param function_id: function to get the type of
315
- // / \return the function's type with its `return_type()` restored to its
316
- // / original value
317
- code_typet original_return_type (
318
- const symbol_table_baset &symbol_table,
319
- const irep_idt &function_id)
320
- {
321
- // look up the function symbol
322
- const symbolt &function_symbol = symbol_table.lookup_ref (function_id);
323
- code_typet type = to_code_type (function_symbol.type );
324
-
325
- // do we have X#return_value?
326
- std::string rv_name=id2string (function_id)+RETURN_VALUE_SUFFIX;
327
-
328
- symbol_tablet::symbolst::const_iterator rv_it=
329
- symbol_table.symbols .find (rv_name);
330
-
331
- if (rv_it != symbol_table.symbols .end ())
332
- type.return_type () = rv_it->second .type ;
333
-
334
- return type;
335
- }
336
-
337
288
// / turns an assignment to fkt#return_value back into 'return x'
338
289
bool remove_returnst::restore_returns (
339
290
goto_functionst::function_mapt::iterator f_it)
@@ -349,13 +300,6 @@ bool remove_returnst::restore_returns(
349
300
if (rv_it==symbol_table.symbols .end ())
350
301
return true ;
351
302
352
- // look up the function symbol
353
- symbolt &function_symbol=*symbol_table.get_writeable (function_id);
354
-
355
- // restore the return type
356
- f_it->second .type =original_return_type (symbol_table, function_id);
357
- function_symbol.type =f_it->second .type ;
358
-
359
303
// remove the return_value symbol from the symbol_table
360
304
irep_idt rv_name_id=rv_it->second .name ;
361
305
symbol_table.erase (rv_it);
@@ -407,12 +351,6 @@ void remove_returnst::undo_function_calls(
407
351
const irep_idt function_id=
408
352
to_symbol_expr (function_call.function ()).get_identifier ();
409
353
410
- const symbolt &function_symbol=ns.lookup (function_id);
411
-
412
- // fix the type
413
- to_code_type (function_call.function ().type ()).return_type ()=
414
- to_code_type (function_symbol.type ).return_type ();
415
-
416
354
// find "f(...); lhs=f#return_value; DEAD f#return_value;"
417
355
// and revert to "lhs=f(...);"
418
356
goto_programt::instructionst::iterator next = std::next (i_it);
0 commit comments