Skip to content

Commit 556375e

Browse files
committed
Run remove_skip 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 b7e87ea commit 556375e

9 files changed

+69
-17
lines changed

src/analyses/goto_check.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Author: Daniel Kroening, [email protected]
3131
#include <langapi/language.h>
3232
#include <langapi/mode.h>
3333

34+
#include <goto-programs/remove_skip.h>
35+
3436
#include "local_bitvector_analysis.h"
3537

3638
class goto_checkt
@@ -1475,6 +1477,8 @@ void goto_checkt::goto_check(
14751477
assertions.clear();
14761478
mode = _mode;
14771479

1480+
bool did_something = false;
1481+
14781482
local_bitvector_analysist local_bitvector_analysis_obj(goto_function);
14791483
local_bitvector_analysis=&local_bitvector_analysis_obj;
14801484

@@ -1625,13 +1629,15 @@ void goto_checkt::goto_check(
16251629
(!is_user_provided && !enable_built_in_assertions))
16261630
{
16271631
i.make_skip();
1632+
did_something = true;
16281633
}
16291634
}
16301635
else if(i.is_assume())
16311636
{
16321637
if(!enable_assumptions)
16331638
{
16341639
i.make_skip();
1640+
did_something = true;
16351641
}
16361642
}
16371643
else if(i.is_dead())
@@ -1719,6 +1725,7 @@ void goto_checkt::goto_check(
17191725
}
17201726

17211727
// insert new instructions -- make sure targets are not moved
1728+
did_something |= !new_code.instructions.empty();
17221729

17231730
while(!new_code.instructions.empty())
17241731
{
@@ -1727,6 +1734,9 @@ void goto_checkt::goto_check(
17271734
it++;
17281735
}
17291736
}
1737+
1738+
if(did_something)
1739+
remove_skip(goto_program);
17301740
}
17311741

17321742
void goto_check(

src/goto-instrument/cover.cpp

+3-1
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,7 @@ static void instrument_cover_goals(
283285
}
284286

285287
if(changed)
286-
function.body.update();
288+
remove_skip(function.body);
287289
}
288290

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

src/goto-instrument/goto_instrument_parse_options.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ int goto_instrument_parse_optionst::doit()
204204
goto_unwindt goto_unwind;
205205
goto_unwind(goto_model, unwind_set, k, unwind_strategy);
206206

207-
goto_model.goto_functions.update();
208-
goto_model.goto_functions.compute_loop_numbers();
209-
210207
if(cmdline.isset("log"))
211208
{
212209
std::string filename=cmdline.get_value("log");
@@ -232,6 +229,10 @@ int goto_instrument_parse_optionst::doit()
232229
std::cout << result << '\n';
233230
}
234231
}
232+
233+
// goto_unwind holds references to instructions, only do remove_skip
234+
// after having generated the log above
235+
remove_skip(goto_model);
235236
}
236237
}
237238

src/goto-programs/generate_function_bodies.cpp

+4
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,8 @@ 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);
317321
}
318322

319323
private:

src/goto-programs/remove_asm.cpp

+8
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,26 @@ 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+
remove_skip(goto_function.body);
298306
}
299307

300308
/// removes assembler

src/goto-programs/remove_returns.cpp

+8
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,13 @@ 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+
remove_skip(goto_program);
396+
389397
return false;
390398
}
391399

src/goto-programs/remove_virtual_functions.cpp

+9-5
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>
@@ -135,6 +135,7 @@ void remove_virtual_functionst::remove_virtual_function(
135135
if(functions.empty())
136136
{
137137
target->make_skip();
138+
remove_skip(goto_program, target, std::next(target));
138139
return; // give up
139140
}
140141

@@ -143,7 +144,10 @@ void remove_virtual_functionst::remove_virtual_function(
143144
fallback_action==virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION)
144145
{
145146
if(functions.begin()->symbol_expr==symbol_exprt())
147+
{
146148
target->make_skip();
149+
remove_skip(goto_program, target, std::next(target));
150+
}
147151
else
148152
{
149153
create_static_function_call(
@@ -290,6 +294,8 @@ void remove_virtual_functionst::remove_virtual_function(
290294

291295
// finally, kill original invocation
292296
target->make_skip();
297+
298+
remove_skip(goto_program, target, next_target);
293299
}
294300

295301
/// Used by get_functions to track the most-derived parent that provides an
@@ -486,9 +492,7 @@ bool remove_virtual_functionst::remove_virtual_functions(
486492
}
487493

488494
if(did_something)
489-
{
490-
goto_program.update();
491-
}
495+
remove_skip(goto_program);
492496

493497
return did_something;
494498
}

src/goto-programs/string_instrumentation.cpp

+2-1
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,7 +267,7 @@ void string_instrumentationt::do_function_call(
266267
else if(identifier=="fscanf")
267268
do_fscanf(dest, target, call);
268269

269-
dest.update();
270+
remove_skip(dest);
270271
}
271272
}
272273

src/java_bytecode/remove_exceptions.cpp

+21-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,22 @@ 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+
remove_skip(goto_program);
552566
}
553567

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

0 commit comments

Comments
 (0)