Skip to content

Commit fa4bd99

Browse files
committed
Run remove_skip and goto_program.update() in passes that may introduce skips
The only passes left out are set_properties and remove_unreachable as the caller may still find value in those instructions replaced by a skip. (This need not be true and it may as well be safe to run remove_skip for those as well.) Fixes: diffblue#2067
1 parent a569e98 commit fa4bd99

9 files changed

+82
-12
lines changed

src/analyses/goto_check.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Author: Daniel Kroening, [email protected]
2828
#include <util/cprover_prefix.h>
2929
#include <util/options.h>
3030

31+
#include <goto-programs/remove_skip.h>
32+
3133
#include <langapi/language_util.h>
3234

3335
#include "local_bitvector_analysis.h"
@@ -1477,6 +1479,7 @@ void goto_checkt::goto_check(
14771479
const irep_idt &mode)
14781480
{
14791481
assertions.clear();
1482+
bool did_something = false;
14801483

14811484
local_bitvector_analysist local_bitvector_analysis_obj(goto_function);
14821485
local_bitvector_analysis=&local_bitvector_analysis_obj;
@@ -1628,13 +1631,15 @@ void goto_checkt::goto_check(
16281631
(!is_user_provided && !enable_built_in_assertions))
16291632
{
16301633
i.make_skip();
1634+
did_something = true;
16311635
}
16321636
}
16331637
else if(i.is_assume())
16341638
{
16351639
if(!enable_assumptions)
16361640
{
16371641
i.make_skip();
1642+
did_something = true;
16381643
}
16391644
}
16401645
else if(i.is_dead())
@@ -1722,6 +1727,7 @@ void goto_checkt::goto_check(
17221727
}
17231728

17241729
// insert new instructions -- make sure targets are not moved
1730+
did_something |= !new_code.instructions.empty();
17251731

17261732
while(!new_code.instructions.empty())
17271733
{
@@ -1730,6 +1736,12 @@ void goto_checkt::goto_check(
17301736
it++;
17311737
}
17321738
}
1739+
1740+
if(did_something)
1741+
{
1742+
remove_skip(goto_program);
1743+
goto_program.update();
1744+
}
17331745
}
17341746

17351747
void goto_check(

src/goto-instrument/cover.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Date: May 2016
2020
#include <util/options.h>
2121
#include <util/deprecate.h>
2222

23+
#include <goto-programs/remove_skip.h>
24+
2325
#include "cover_basic_blocks.h"
2426

2527
/// Applies instrumenters to given goto program
@@ -283,7 +285,10 @@ static void instrument_cover_goals(
283285
}
284286

285287
if(changed)
288+
{
289+
remove_skip(function.body);
286290
function.body.update();
291+
}
287292
}
288293

289294
/// Instruments a single goto program based on the given configuration

src/goto-instrument/goto_instrument_parse_options.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ int goto_instrument_parse_optionst::doit()
207207
goto_unwindt goto_unwind;
208208
goto_unwind(goto_model, unwind_set, k, unwind_strategy);
209209

210-
goto_model.goto_functions.update();
211-
goto_model.goto_functions.compute_loop_numbers();
212-
213210
if(cmdline.isset("log"))
214211
{
215212
std::string filename=cmdline.get_value("log");
@@ -235,6 +232,12 @@ int goto_instrument_parse_optionst::doit()
235232
std::cout << result << '\n';
236233
}
237234
}
235+
236+
// goto_unwind holds references to instructions, only do remove_skip
237+
// after having generated the log above
238+
remove_skip(goto_model);
239+
goto_model.goto_functions.update();
240+
goto_model.goto_functions.compute_loop_numbers();
238241
}
239242
}
240243

src/goto-programs/generate_function_bodies.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author: Diffblue Ltd.
2020
#include <util/pointer_offset_size.h>
2121
#include <util/arith_tools.h>
2222

23+
#include "remove_skip.h"
24+
2325
void generate_function_bodiest::generate_function_body(
2426
goto_functiont &function,
2527
symbol_tablet &symbol_table,
@@ -314,6 +316,9 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
314316
}
315317
auto end_function_instruction = add_instruction();
316318
end_function_instruction->make_end_function();
319+
320+
remove_skip(function.body);
321+
function.body.update();
317322
}
318323

319324
private:

src/goto-programs/remove_asm.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Date: December 2014
2222

2323
#include <assembler/assembler_parser.h>
2424

25+
#include "remove_skip.h"
26+
2527
class remove_asmt
2628
{
2729
public:
@@ -281,20 +283,29 @@ void remove_asmt::process_instruction(
281283
void remove_asmt::process_function(
282284
goto_functionst::goto_functiont &goto_function)
283285
{
286+
bool did_something = false;
287+
284288
Forall_goto_program_instructions(it, goto_function.body)
285289
{
286290
if(it->is_other() && it->code.get_statement()==ID_asm)
287291
{
288292
goto_programt tmp_dest;
289293
process_instruction(*it, tmp_dest);
290294
it->make_skip();
295+
did_something = true;
291296

292297
goto_programt::targett next=it;
293298
next++;
294299

295300
goto_function.body.destructive_insert(next, tmp_dest);
296301
}
297302
}
303+
304+
if(did_something)
305+
{
306+
remove_skip(goto_function.body);
307+
goto_function.body.update();
308+
}
298309
}
299310

300311
/// removes assembler

src/goto-programs/remove_returns.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: September 2009
1616
#include <util/std_expr.h>
1717
#include <util/symbol_table.h>
1818

19+
#include "remove_skip.h"
20+
1921
class remove_returnst
2022
{
2123
public:
@@ -341,6 +343,8 @@ bool remove_returnst::restore_returns(
341343

342344
goto_programt &goto_program=f_it->second.body;
343345

346+
bool did_something = false;
347+
344348
Forall_goto_program_instructions(i_it, goto_program)
345349
{
346350
if(i_it->is_assign())
@@ -383,9 +387,16 @@ bool remove_returnst::restore_returns(
383387

384388
i_it->make_return();
385389
i_it->code=return_code;
390+
did_something = true;
386391
}
387392
}
388393

394+
if(did_something)
395+
{
396+
remove_skip(goto_program);
397+
goto_program.update();
398+
}
399+
389400
return false;
390401
}
391402

src/goto-programs/remove_virtual_functions.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Author: Daniel Kroening, [email protected]
1313
#include "remove_virtual_functions.h"
1414
#include "class_hierarchy.h"
1515
#include "class_identifier.h"
16-
17-
#include <goto-programs/resolve_inherited_component.h>
16+
#include "remove_skip.h"
17+
#include "resolve_inherited_component.h"
1818

1919
#include <util/c_types.h>
2020
#include <util/prefix.h>
@@ -487,6 +487,7 @@ bool remove_virtual_functionst::remove_virtual_functions(
487487

488488
if(did_something)
489489
{
490+
remove_skip(goto_program);
490491
goto_program.update();
491492
}
492493

@@ -549,6 +550,9 @@ void remove_virtual_function(
549550

550551
rvf.remove_virtual_function(
551552
goto_program, instruction, dispatch_table, fallback_action);
553+
554+
remove_skip(goto_program);
555+
goto_program.update();
552556
}
553557

554558
void remove_virtual_function(

src/goto-programs/string_instrumentation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323

2424
#include <goto-programs/format_strings.h>
2525
#include <goto-programs/goto_model.h>
26+
#include <goto-programs/remove_skip.h>
2627

2728

2829
exprt is_zero_string(
@@ -266,6 +267,7 @@ void string_instrumentationt::do_function_call(
266267
else if(identifier=="fscanf")
267268
do_fscanf(dest, target, call);
268269

270+
remove_skip(dest);
269271
dest.update();
270272
}
271273
}

src/java_bytecode/remove_exceptions.cpp

+24-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Date: December 2016
2626
#include <util/std_code.h>
2727
#include <util/symbol_table.h>
2828

29+
#include <goto-programs/remove_skip.h>
30+
2931
#include <analyses/uncaught_exceptions_analysis.h>
3032

3133
/// Lowers high-level exception descriptions into low-level operations suitable
@@ -122,13 +124,13 @@ class remove_exceptionst
122124
const stack_catcht &stack_catch,
123125
const std::vector<exprt> &locals);
124126

125-
void instrument_throw(
127+
bool instrument_throw(
126128
goto_programt &goto_program,
127129
const goto_programt::targett &,
128130
const stack_catcht &,
129131
const std::vector<exprt> &);
130132

131-
void instrument_function_call(
133+
bool instrument_function_call(
132134
goto_programt &goto_program,
133135
const goto_programt::targett &,
134136
const stack_catcht &,
@@ -369,7 +371,7 @@ void remove_exceptionst::add_exception_dispatch_sequence(
369371

370372
/// instruments each throw with conditional GOTOS to the corresponding
371373
/// exception handlers
372-
void remove_exceptionst::instrument_throw(
374+
bool remove_exceptionst::instrument_throw(
373375
goto_programt &goto_program,
374376
const goto_programt::targett &instr_it,
375377
const remove_exceptionst::stack_catcht &stack_catch,
@@ -387,7 +389,7 @@ void remove_exceptionst::instrument_throw(
387389
// and this may reduce the instrumentation considerably if the programmer
388390
// used assertions)
389391
if(assertion_error)
390-
return;
392+
return false;
391393

392394
add_exception_dispatch_sequence(
393395
goto_program, instr_it, stack_catch, locals);
@@ -403,11 +405,13 @@ void remove_exceptionst::instrument_throw(
403405
// now turn the `throw' into `assignment'
404406
instr_it->type=ASSIGN;
405407
instr_it->code=assignment;
408+
409+
return true;
406410
}
407411

408412
/// instruments each function call that may escape exceptions with conditional
409413
/// GOTOS to the corresponding exception handlers
410-
void remove_exceptionst::instrument_function_call(
414+
bool remove_exceptionst::instrument_function_call(
411415
goto_programt &goto_program,
412416
const goto_programt::targett &instr_it,
413417
const stack_catcht &stack_catch,
@@ -441,7 +445,11 @@ void remove_exceptionst::instrument_function_call(
441445
t_null->source_location=instr_it->source_location;
442446
t_null->function=instr_it->function;
443447
t_null->guard=eq_null;
448+
449+
return true;
444450
}
451+
452+
return false;
445453
}
446454

447455
/// instruments throws, function calls that may escape exceptions and exception
@@ -460,6 +468,8 @@ void remove_exceptionst::instrument_exceptions(
460468
bool program_or_callees_may_throw =
461469
function_or_callees_may_throw(goto_program);
462470

471+
bool did_something = false;
472+
463473
Forall_goto_program_instructions(instr_it, goto_program)
464474
{
465475
if(instr_it->is_decl())
@@ -537,18 +547,25 @@ void remove_exceptionst::instrument_exceptions(
537547
"CATCH opcode should be one of push-catch, pop-catch, landingpad");
538548
}
539549
instr_it->make_skip();
550+
did_something = true;
540551
}
541552
else if(instr_it->type==THROW)
542553
{
543-
instrument_throw(
554+
did_something |= instrument_throw(
544555
goto_program, instr_it, stack_catch, locals);
545556
}
546557
else if(instr_it->type==FUNCTION_CALL)
547558
{
548-
instrument_function_call(
559+
did_something |= instrument_function_call(
549560
goto_program, instr_it, stack_catch, locals);
550561
}
551562
}
563+
564+
if(did_something)
565+
{
566+
remove_skip(goto_program);
567+
goto_program.update();
568+
}
552569
}
553570

554571
void remove_exceptionst::operator()(goto_functionst &goto_functions)

0 commit comments

Comments
 (0)