Skip to content

Commit 083d8a6

Browse files
Always report exceptinal output in __CPROVER_start
1 parent 8fd1118 commit 083d8a6

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/goto-programs/remove_exceptions.cpp

+41-6
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,39 @@ void remove_exceptionst::instrument_exception_handler(
192192

193193
/*******************************************************************\
194194
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+
195228
Function: remove_exceptionst::instrument_throw
196229
197230
Inputs:
@@ -217,13 +250,14 @@ void remove_exceptionst::instrument_throw(
217250
assert(instr_it->code.operands().size()==1);
218251

219252
// 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)
222256
{
223257
// jump to the end of the function
224258
// this will appear after the GOTO-based dynamic dispatch below
225259
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);
227261
t_end->source_location=instr_it->source_location;
228262
t_end->function=instr_it->function;
229263
}
@@ -322,13 +356,14 @@ void remove_exceptionst::instrument_function_call(
322356
symbol_exprt callee_exc=callee_exc_symbol.symbol_expr();
323357

324358
// 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)
327362
{
328363
// jump to the end of the function
329364
// this will appear after the GOTO-based dynamic dispatch below
330365
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);
332367
t_end->source_location=instr_it->source_location;
333368
t_end->function=instr_it->function;
334369
}

0 commit comments

Comments
 (0)