Skip to content

Commit 6bac80e

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 533775c commit 6bac80e

10 files changed

+100
-35
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

+23-9
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(
544-
goto_program, instr_it, stack_catch, locals);
554+
did_something |=
555+
instrument_throw(goto_program, instr_it, stack_catch, locals);
545556
}
546557
else if(instr_it->type==FUNCTION_CALL)
547558
{
548-
instrument_function_call(
549-
goto_program, instr_it, stack_catch, locals);
559+
did_something |=
560+
instrument_function_call(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)

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
@@ -1501,6 +1503,8 @@ void goto_checkt::goto_check(
15011503
assertions.clear();
15021504
mode = _mode;
15031505

1506+
bool did_something = false;
1507+
15041508
local_bitvector_analysist local_bitvector_analysis_obj(goto_function);
15051509
local_bitvector_analysis=&local_bitvector_analysis_obj;
15061510

@@ -1651,13 +1655,15 @@ void goto_checkt::goto_check(
16511655
(!is_user_provided && !enable_built_in_assertions))
16521656
{
16531657
i.make_skip();
1658+
did_something = true;
16541659
}
16551660
}
16561661
else if(i.is_assume())
16571662
{
16581663
if(!enable_assumptions)
16591664
{
16601665
i.make_skip();
1666+
did_something = true;
16611667
}
16621668
}
16631669
else if(i.is_dead())
@@ -1745,6 +1751,7 @@ void goto_checkt::goto_check(
17451751
}
17461752

17471753
// insert new instructions -- make sure targets are not moved
1754+
did_something |= !new_code.instructions.empty();
17481755

17491756
while(!new_code.instructions.empty())
17501757
{
@@ -1753,6 +1760,9 @@ void goto_checkt::goto_check(
17531760
it++;
17541761
}
17551762
}
1763+
1764+
if(did_something)
1765+
remove_skip(goto_program);
17561766
}
17571767

17581768
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
@@ -293,7 +295,7 @@ static void instrument_cover_goals(
293295
}
294296

295297
if(changed)
296-
function.body.update();
298+
remove_skip(function.body);
297299
}
298300

299301
/// 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
@@ -174,9 +174,6 @@ int goto_instrument_parse_optionst::doit()
174174
goto_unwindt goto_unwind;
175175
goto_unwind(goto_model, unwindset, unwind_strategy);
176176

177-
goto_model.goto_functions.update();
178-
goto_model.goto_functions.compute_loop_numbers();
179-
180177
if(cmdline.isset("log"))
181178
{
182179
std::string filename=cmdline.get_value("log");
@@ -202,6 +199,10 @@ int goto_instrument_parse_optionst::doit()
202199
std::cout << result << '\n';
203200
}
204201
}
202+
203+
// goto_unwind holds references to instructions, only do remove_skip
204+
// after having generated the log above
205+
remove_skip(goto_model);
205206
}
206207
}
207208

src/goto-programs/generate_function_bodies.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Diffblue Ltd.
1313
#include <util/make_unique.h>
1414
#include <util/string_utils.h>
1515

16+
#include "remove_skip.h"
17+
1618
void generate_function_bodiest::generate_function_body(
1719
goto_functiont &function,
1820
symbol_tablet &symbol_table,
@@ -307,6 +309,8 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
307309
}
308310
auto end_function_instruction = add_instruction();
309311
end_function_instruction->make_end_function();
312+
313+
remove_skip(function.body);
310314
}
311315

312316
private:

src/goto-programs/remove_asm.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Date: December 2014
2020
#include <assembler/assembler_parser.h>
2121

2222
#include "goto_model.h"
23+
#include "remove_skip.h"
2324

2425
class remove_asmt
2526
{
@@ -280,20 +281,26 @@ void remove_asmt::process_instruction(
280281
void remove_asmt::process_function(
281282
goto_functionst::goto_functiont &goto_function)
282283
{
284+
bool did_something = false;
285+
283286
Forall_goto_program_instructions(it, goto_function.body)
284287
{
285288
if(it->is_other() && it->code.get_statement()==ID_asm)
286289
{
287290
goto_programt tmp_dest;
288291
process_instruction(*it, tmp_dest);
289292
it->make_skip();
293+
did_something = true;
290294

291295
goto_programt::targett next=it;
292296
next++;
293297

294298
goto_function.body.destructive_insert(next, tmp_dest);
295299
}
296300
}
301+
302+
if(did_something)
303+
remove_skip(goto_function.body);
297304
}
298305

299306
/// removes assembler

src/goto-programs/remove_returns.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Date: September 2009
1717

1818
#include "goto_model.h"
1919

20+
#include "remove_skip.h"
21+
2022
class remove_returnst
2123
{
2224
public:
@@ -342,6 +344,8 @@ bool remove_returnst::restore_returns(
342344

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

347+
bool did_something = false;
348+
345349
Forall_goto_program_instructions(i_it, goto_program)
346350
{
347351
if(i_it->is_assign())
@@ -355,9 +359,13 @@ bool remove_returnst::restore_returns(
355359
const exprt rhs = assign.rhs();
356360
i_it->make_return();
357361
i_it->code = code_returnt(rhs);
362+
did_something = true;
358363
}
359364
}
360365

366+
if(did_something)
367+
remove_skip(goto_program);
368+
361369
return false;
362370
}
363371

0 commit comments

Comments
 (0)