Skip to content

Commit 845d60d

Browse files
committed
Update location numbers after adding instructions
remove_returnst::do_function_calls may introduce new instructions. Doing so requires a call to compute_location_numbers to ensure instruction numbers are assigned. To avoid recomputing location numbers across all goto functions, the facility from goto_functionst is used, which will ensure globally unique location numbers (though they might not be globally contiguous).
1 parent 5225ab6 commit 845d60d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/goto-programs/remove_returns.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class remove_returnst
4444
const irep_idt &function_id,
4545
goto_functionst::goto_functiont &function);
4646

47-
void do_function_calls(
47+
bool do_function_calls(
4848
function_is_stubt function_is_stub,
4949
goto_programt &goto_program);
5050

@@ -142,10 +142,14 @@ void remove_returnst::replace_returns(
142142
/// \param function_is_stub: function (irep_idt -> bool) that determines whether
143143
/// a given function ID is a stub
144144
/// \param goto_program: program to transform
145-
void remove_returnst::do_function_calls(
145+
/// \return True if, and only if, instructions have been inserted. In that case
146+
/// the caller must invoke an appropriate method to update location numbers.
147+
bool remove_returnst::do_function_calls(
146148
function_is_stubt function_is_stub,
147149
goto_programt &goto_program)
148150
{
151+
bool requires_update = false;
152+
149153
Forall_goto_program_instructions(i_it, goto_program)
150154
{
151155
if(i_it->is_function_call())
@@ -221,13 +225,17 @@ void remove_returnst::do_function_calls(
221225
t_a,
222226
goto_programt::make_dead(*return_value, i_it->source_location));
223227
}
228+
229+
requires_update = true;
224230
}
225231

226232
// update the call
227233
i_it->set_function_call(function_call);
228234
}
229235
}
230236
}
237+
238+
return requires_update;
231239
}
232240

233241
void remove_returnst::operator()(goto_functionst &goto_functions)
@@ -244,7 +252,8 @@ void remove_returnst::operator()(goto_functionst &goto_functions)
244252
};
245253

246254
replace_returns(it->first, it->second);
247-
do_function_calls(function_is_stub, it->second.body);
255+
if(do_function_calls(function_is_stub, it->second.body))
256+
goto_functions.compute_location_numbers(it->second.body);
248257
}
249258
}
250259

@@ -261,7 +270,8 @@ void remove_returnst::operator()(
261270
return;
262271

263272
replace_returns(model_function.get_function_id(), goto_function);
264-
do_function_calls(function_is_stub, goto_function.body);
273+
if(do_function_calls(function_is_stub, goto_function.body))
274+
model_function.compute_location_numbers();
265275
}
266276

267277
/// removes returns

0 commit comments

Comments
 (0)