@@ -192,6 +192,39 @@ void remove_exceptionst::instrument_exception_handler(
192
192
193
193
/* ******************************************************************\
194
194
195
+ Function: get_exceptional_output
196
+
197
+ Inputs:
198
+
199
+ Outputs:
200
+
201
+ Purpose: finds the instruction where the exceptional output is set
202
+ or the end of the function if no such output exists
203
+
204
+ \*******************************************************************/
205
+
206
+ static goto_programt::targett get_exceptional_output (
207
+ goto_programt &goto_program)
208
+ {
209
+ Forall_goto_program_instructions (it, goto_program)
210
+ {
211
+ const irep_idt &statement=it->code .get_statement ();
212
+ if (statement==ID_output)
213
+ {
214
+ assert (it->code .operands ().size ()>=2 );
215
+ const exprt &expr=it->code .op1 ();
216
+ assert (expr.id ()==ID_symbol);
217
+ const symbol_exprt &symbol=to_symbol_expr (expr);
218
+ if (id2string (symbol.get_identifier ()).find (EXC_SUFFIX)
219
+ !=std::string::npos)
220
+ return it;
221
+ }
222
+ }
223
+ return goto_program.get_end_function ();
224
+ }
225
+
226
+ /* ******************************************************************\
227
+
195
228
Function: remove_exceptionst::instrument_throw
196
229
197
230
Inputs:
@@ -217,13 +250,14 @@ void remove_exceptionst::instrument_throw(
217
250
assert (instr_it->code .operands ().size ()==1 );
218
251
219
252
// find the end of the function
220
- goto_programt::targett end_function=goto_program.get_end_function ();
221
- if (end_function!=instr_it)
253
+ goto_programt::targett exceptional_output=
254
+ get_exceptional_output (goto_program);
255
+ if (exceptional_output!=instr_it)
222
256
{
223
257
// jump to the end of the function
224
258
// this will appear after the GOTO-based dynamic dispatch below
225
259
goto_programt::targett t_end=goto_program.insert_after (instr_it);
226
- t_end->make_goto (end_function );
260
+ t_end->make_goto (exceptional_output );
227
261
t_end->source_location =instr_it->source_location ;
228
262
t_end->function =instr_it->function ;
229
263
}
@@ -322,13 +356,14 @@ void remove_exceptionst::instrument_function_call(
322
356
symbol_exprt callee_exc=callee_exc_symbol.symbol_expr ();
323
357
324
358
// find the end of the function
325
- goto_programt::targett end_function=goto_program.get_end_function ();
326
- if (end_function!=instr_it)
359
+ goto_programt::targett exceptional_output=
360
+ get_exceptional_output (goto_program);
361
+ if (exceptional_output!=instr_it)
327
362
{
328
363
// jump to the end of the function
329
364
// this will appear after the GOTO-based dynamic dispatch below
330
365
goto_programt::targett t_end=goto_program.insert_after (instr_it);
331
- t_end->make_goto (end_function );
366
+ t_end->make_goto (exceptional_output );
332
367
t_end->source_location =instr_it->source_location ;
333
368
t_end->function =instr_it->function ;
334
369
}
0 commit comments