Skip to content

Commit 94b7658

Browse files
Don't pass iterators into function calls
1 parent ddd1b7a commit 94b7658

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

src/goto-programs/remove_exceptions.cpp

+45-43
Original file line numberDiff line numberDiff line change
@@ -90,49 +90,53 @@ class remove_exceptionst
9090
{
9191
}
9292

93-
void operator()(
94-
goto_functionst &goto_functions);
93+
void operator()(goto_functionst &goto_functions);
9594

9695
protected:
9796
symbol_tablet &symbol_table;
9897
std::map<irep_idt, std::set<irep_idt>> &exceptions_map;
9998

10099
void add_exceptional_returns(
101-
const goto_functionst::function_mapt::iterator &);
100+
const irep_idt &function_id,
101+
goto_programt &goto_program);
102102

103103
void instrument_exception_handler(
104-
const goto_functionst::function_mapt::iterator &,
104+
const irep_idt &function_id,
105+
goto_programt &goto_program,
105106
const goto_programt::targett &);
106107

107108
void add_exception_dispatch_sequence(
108-
const goto_functionst::function_mapt::iterator &,
109+
const irep_idt &function_id,
110+
goto_programt &goto_program,
109111
const goto_programt::targett &instr_it,
110112
const stack_catcht &stack_catch,
111113
const std::vector<exprt> &locals);
112114

113115
void instrument_throw(
114-
const goto_functionst::function_mapt::iterator &,
116+
const irep_idt &function_id,
117+
goto_programt &goto_program,
115118
const goto_programt::targett &,
116119
const stack_catcht &,
117120
const std::vector<exprt> &);
118121

119122
void instrument_function_call(
120-
const goto_functionst::function_mapt::iterator &,
123+
const irep_idt &function_id,
124+
goto_programt &goto_program,
121125
const goto_programt::targett &,
122126
const stack_catcht &,
123127
const std::vector<exprt> &);
124128

125129
void instrument_exceptions(
126-
const goto_functionst::function_mapt::iterator &);
130+
const irep_idt &function_id,
131+
goto_programt &goto_program);
127132
};
128133

129134
/// adds exceptional return variables for every function that may escape
130135
/// exceptions
131136
void remove_exceptionst::add_exceptional_returns(
132-
const goto_functionst::function_mapt::iterator &func_it)
137+
const irep_idt &function_id,
138+
goto_programt &goto_program)
133139
{
134-
const irep_idt &function_id=func_it->first;
135-
goto_programt &goto_program=func_it->second.body;
136140

137141
auto maybe_symbol=symbol_table.lookup(function_id);
138142
INVARIANT(maybe_symbol, "functions should be recorded in the symbol table");
@@ -236,17 +240,17 @@ void remove_exceptionst::add_exceptional_returns(
236240
/// Translates an exception landing-pad into instructions that copy the
237241
/// in-flight exception pointer to a nominated expression, then clear the
238242
/// in-flight exception (i.e. null the pointer), hence marking it caught.
239-
/// \param func_it: iterator pointing to the function containing this
240-
/// landingpad instruction
241-
/// \param instr_it [in, out]: iterator pointing to the landingpad instruction.
243+
/// \param function_id: name of the function containing this landingpad
244+
/// instruction
245+
/// \param goto_program: body of the function containing this landingpad
246+
/// instruction
247+
/// \param instr_it: iterator pointing to the landingpad instruction.
242248
/// Will be overwritten.
243249
void remove_exceptionst::instrument_exception_handler(
244-
const goto_functionst::function_mapt::iterator &func_it,
250+
const irep_idt &function_id,
251+
goto_programt &goto_program,
245252
const goto_programt::targett &instr_it)
246253
{
247-
const irep_idt &function_id=func_it->first;
248-
goto_programt &goto_program=func_it->second.body;
249-
250254
PRECONDITION(instr_it->type==CATCH);
251255

252256
// retrieve the exception variable
@@ -285,20 +289,19 @@ void remove_exceptionst::instrument_exception_handler(
285289
/// if (exception instanceof ExnA) then goto handlerA
286290
/// else if (exception instanceof ExnB) then goto handlerB
287291
/// else goto universal_handler or (dead locals; function exit)
288-
/// \param func_it: iterator pointing to function instr_it belongs to
292+
/// \param function_id: name of the function to which instr_it belongs
293+
/// \param goto_program: body of the function to which instr_it belongs
289294
/// \param instr_it: throw or call instruction that may be an
290295
/// exception source
291296
/// \param stack_catch: exception handlers currently registered
292297
/// \param locals: local variables to kill on a function-exit edge
293298
void remove_exceptionst::add_exception_dispatch_sequence(
294-
const goto_functionst::function_mapt::iterator &func_it,
299+
const irep_idt &function_id,
300+
goto_programt &goto_program,
295301
const goto_programt::targett &instr_it,
296302
const remove_exceptionst::stack_catcht &stack_catch,
297303
const std::vector<exprt> &locals)
298304
{
299-
const irep_idt &function_id=func_it->first;
300-
goto_programt &goto_program=func_it->second.body;
301-
302305
// Unless we have a universal exception handler, jump to end of function
303306
// if not caught:
304307
goto_programt::targett default_target=goto_program.get_end_function();
@@ -360,10 +363,11 @@ void remove_exceptionst::add_exception_dispatch_sequence(
360363
}
361364
}
362365

363-
/// instruments each throw with conditional GOTOS to the corresponding
366+
/// instruments each throw with conditional GOTOS to the corresponding
364367
/// exception handlers
365368
void remove_exceptionst::instrument_throw(
366-
const goto_functionst::function_mapt::iterator &func_it,
369+
const irep_idt &function_id,
370+
goto_programt &goto_program,
367371
const goto_programt::targett &instr_it,
368372
const remove_exceptionst::stack_catcht &stack_catch,
369373
const std::vector<exprt> &locals)
@@ -383,11 +387,11 @@ void remove_exceptionst::instrument_throw(
383387
return;
384388

385389
add_exception_dispatch_sequence(
386-
func_it, instr_it, stack_catch, locals);
390+
function_id, goto_program, instr_it, stack_catch, locals);
387391

388392
// find the symbol where the thrown exception should be stored:
389-
const symbolt &exc_symbol=
390-
symbol_table.lookup_ref(id2string(func_it->first)+EXC_SUFFIX);
393+
const symbolt &exc_symbol =
394+
symbol_table.lookup_ref(id2string(function_id) + EXC_SUFFIX);
391395
symbol_exprt exc_thrown=exc_symbol.symbol_expr();
392396

393397
// add the assignment with the appropriate cast
@@ -401,16 +405,14 @@ void remove_exceptionst::instrument_throw(
401405
/// instruments each function call that may escape exceptions with conditional
402406
/// GOTOS to the corresponding exception handlers
403407
void remove_exceptionst::instrument_function_call(
404-
const goto_functionst::function_mapt::iterator &func_it,
408+
const irep_idt &function_id,
409+
goto_programt &goto_program,
405410
const goto_programt::targett &instr_it,
406411
const stack_catcht &stack_catch,
407412
const std::vector<exprt> &locals)
408413
{
409414
PRECONDITION(instr_it->type==FUNCTION_CALL);
410415

411-
goto_programt &goto_program=func_it->second.body;
412-
const irep_idt &function_id=func_it->first;
413-
414416
// save the address of the next instruction
415417
goto_programt::targett next_it=instr_it;
416418
next_it++;
@@ -430,7 +432,7 @@ void remove_exceptionst::instrument_function_call(
430432
if(callee_inflight_exception && local_inflight_exception)
431433
{
432434
add_exception_dispatch_sequence(
433-
func_it, instr_it, stack_catch, locals);
435+
function_id, goto_program, instr_it, stack_catch, locals);
434436

435437
const symbol_exprt callee_inflight_exception_expr=
436438
callee_inflight_exception->symbol_expr();
@@ -463,12 +465,12 @@ void remove_exceptionst::instrument_function_call(
463465
/// handlers. Additionally, it re-computes the live-range of local variables in
464466
/// order to add DEAD instructions.
465467
void remove_exceptionst::instrument_exceptions(
466-
const goto_functionst::function_mapt::iterator &func_it)
468+
const irep_idt &function_id,
469+
goto_programt &goto_program)
467470
{
468471
stack_catcht stack_catch; // stack of try-catch blocks
469472
std::vector<std::vector<exprt>> stack_locals; // stack of local vars
470473
std::vector<exprt> locals;
471-
goto_programt &goto_program=func_it->second.body;
472474

473475
if(goto_program.empty())
474476
return;
@@ -486,7 +488,7 @@ void remove_exceptionst::instrument_exceptions(
486488
// Is it an exception landing pad (start of a catch block)?
487489
if(statement==ID_exception_landingpad)
488490
{
489-
instrument_exception_handler(func_it, instr_it);
491+
instrument_exception_handler(function_id, goto_program, instr_it);
490492
}
491493
// Is it a catch handler pop?
492494
else if(statement==ID_pop_catch)
@@ -551,21 +553,23 @@ void remove_exceptionst::instrument_exceptions(
551553
}
552554
else if(instr_it->type==THROW)
553555
{
554-
instrument_throw(func_it, instr_it, stack_catch, locals);
556+
instrument_throw(
557+
function_id, goto_program, instr_it, stack_catch, locals);
555558
}
556559
else if(instr_it->type==FUNCTION_CALL)
557560
{
558-
instrument_function_call(func_it, instr_it, stack_catch, locals);
561+
instrument_function_call(
562+
function_id, goto_program, instr_it, stack_catch, locals);
559563
}
560564
}
561565
}
562566

563567
void remove_exceptionst::operator()(goto_functionst &goto_functions)
564568
{
565569
Forall_goto_functions(it, goto_functions)
566-
add_exceptional_returns(it);
570+
add_exceptional_returns(it->first, it->second.body);
567571
Forall_goto_functions(it, goto_functions)
568-
instrument_exceptions(it);
572+
instrument_exceptions(it->first, it->second.body);
569573
}
570574

571575
/// removes throws/CATCH-POP/CATCH-PUSH
@@ -583,7 +587,5 @@ void remove_exceptions(
583587
/// removes throws/CATCH-POP/CATCH-PUSH
584588
void remove_exceptions(goto_modelt &goto_model)
585589
{
586-
remove_exceptions(
587-
goto_model.symbol_table,
588-
goto_model.goto_functions);
590+
remove_exceptions(goto_model.symbol_table, goto_model.goto_functions);
589591
}

0 commit comments

Comments
 (0)