Skip to content

Commit 1a4fc92

Browse files
authored
Merge pull request diffblue#2089 from tautschnig/remove-skip-cleanup
Run remove_skip and goto_program.update() in passes that may introduce skips
2 parents 8de6a33 + 15ce938 commit 1a4fc92

35 files changed

+201
-107
lines changed

jbmc/regression/jbmc/generic_class_bound1/test.desc

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Gn.class
66
.*file Gn.java line 6 function java::Gn.\<init\>:\(\)V bytecode-index 1 block 1: FAILED
77
.*file Gn.java line 9 function java::Gn.foo1:\(LGn;\)V bytecode-index 1 block 1: FAILED
88
.*file Gn.java line 10 function java::Gn.foo1:\(LGn;\)V bytecode-index 4 block 2: FAILED
9-
.*file Gn.java line 11 function java::Gn.foo1:\(LGn;\)V bytecode-index 5 block 3: FAILED
109
.*file Gn.java line 13 function java::Gn.main:\(\[Ljava/lang/String;\)V bytecode-index 2 block 2: SATISFIED
1110
--
1211
--

jbmc/regression/jbmc/virtual8/A.class

7 Bytes
Binary file not shown.

jbmc/regression/jbmc/virtual8/B.class

7 Bytes
Binary file not shown.

jbmc/regression/jbmc/virtual8/C.class

7 Bytes
Binary file not shown.

jbmc/regression/jbmc/virtual8/D.class

0 Bytes
Binary file not shown.

jbmc/regression/jbmc/virtual8/E.class

0 Bytes
Binary file not shown.
7 Bytes
Binary file not shown.

jbmc/regression/jbmc/virtual8/Test.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ public static void main() {
1010
}
1111

1212
class A {
13-
void f() { }
13+
int f() { return 0; }
1414
}
1515

1616

1717
class B extends A {
18-
void f() { }
18+
int f() { return 0; }
1919
}
2020

2121
class C extends A {
22-
void f() { }
22+
int f() { return 0; }
2323
}
2424

2525
class D extends C {

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)

jbmc/src/java_bytecode/replace_java_nondet.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ void replace_java_nondet(goto_model_functiont &function)
288288
goto_programt &program = function.get_goto_function().body;
289289
replace_java_nondet(program);
290290

291-
function.compute_location_numbers();
292-
293291
remove_skip(program);
294292
}
295293

@@ -300,8 +298,6 @@ void replace_java_nondet(goto_functionst &goto_functions)
300298
replace_java_nondet(goto_program.second.body);
301299
}
302300

303-
goto_functions.compute_location_numbers();
304-
305301
remove_skip(goto_functions);
306302
}
307303

jbmc/src/jbmc/jbmc_parse_options.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ bool jbmc_parse_optionst::process_goto_functions(
988988

989989
// remove any skips introduced since coverage instrumentation
990990
remove_skip(goto_model);
991-
goto_model.goto_functions.update();
992991
}
993992

994993
catch(const char *e)

src/analyses/goto_check.cpp

+16-2
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

@@ -1649,12 +1653,18 @@ void goto_checkt::goto_check(
16491653
if((is_user_provided && !enable_assertions &&
16501654
i.source_location.get_property_class()!="error label") ||
16511655
(!is_user_provided && !enable_built_in_assertions))
1652-
i.type=SKIP;
1656+
{
1657+
i.make_skip();
1658+
did_something = true;
1659+
}
16531660
}
16541661
else if(i.is_assume())
16551662
{
16561663
if(!enable_assumptions)
1657-
i.type=SKIP;
1664+
{
1665+
i.make_skip();
1666+
did_something = true;
1667+
}
16581668
}
16591669
else if(i.is_dead())
16601670
{
@@ -1741,6 +1751,7 @@ void goto_checkt::goto_check(
17411751
}
17421752

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

17451756
while(!new_code.instructions.empty())
17461757
{
@@ -1749,6 +1760,9 @@ void goto_checkt::goto_check(
17491760
it++;
17501761
}
17511762
}
1763+
1764+
if(did_something)
1765+
remove_skip(goto_program);
17521766
}
17531767

17541768
void goto_check(

src/goto-analyzer/static_simplifier.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,13 @@ bool static_simplifier(
158158
m.status() << "Removing unreachable instructions" << messaget::eom;
159159

160160
// Removes goto false
161-
remove_skip(goto_model.goto_functions);
162-
goto_model.goto_functions.update();
161+
remove_skip(goto_model);
163162

164163
// Convert unreachable to skips
165164
remove_unreachable(goto_model.goto_functions);
166-
goto_model.goto_functions.update();
167165

168166
// Remove all of the new skips
169-
remove_skip(goto_model.goto_functions);
170-
goto_model.goto_functions.update();
167+
remove_skip(goto_model);
171168
}
172169

173170
// restore return types before writing the binary

src/goto-diff/change_impact.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ void full_slicert::operator()(
132132

133133
// remove the skips
134134
remove_skip(goto_functions);
135-
goto_functions.update();
136135
}
137136

138137

src/goto-diff/goto_diff_parse_options.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ bool goto_diff_parse_optionst::process_goto_program(
425425
// add loop ids
426426
goto_model.goto_functions.compute_loop_numbers();
427427

428-
// remove skips such that trivial GOTOs are deleted and not considered
429-
// for coverage annotation:
430-
remove_skip(goto_model);
431-
432428
// instrument cover goals
433429
if(cmdline.isset("cover"))
434430
{
431+
// remove skips such that trivial GOTOs are deleted and not considered
432+
// for coverage annotation:
433+
remove_skip(goto_model);
434+
435435
if(instrument_cover_goals(options, goto_model, get_message_handler()))
436436
return true;
437437
}
@@ -445,7 +445,6 @@ bool goto_diff_parse_optionst::process_goto_program(
445445

446446
// remove any skips introduced since coverage instrumentation
447447
remove_skip(goto_model);
448-
goto_model.goto_functions.update();
449448
}
450449

451450
catch(const char *e)

src/goto-instrument/accelerate/acceleration_utils.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Author: Matt Lewis
2121

2222
#include <goto-programs/goto_program.h>
2323
#include <goto-programs/wp.h>
24-
#include <goto-programs/remove_skip.h>
2524
#include <goto-programs/goto_functions.h>
2625

2726
#include <goto-symex/goto_symex.h>

src/goto-instrument/accelerate/scratch_program.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ bool scratch_programt::check_sat(bool do_slice)
2929
add_instruction(END_FUNCTION);
3030

3131
remove_skip(*this);
32-
update();
3332

3433
#ifdef DEBUG
3534
std::cout << "Checking following program for satness:\n";

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/full_slicer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ void full_slicert::operator()(
364364

365365
// remove the skips
366366
remove_skip(goto_functions);
367-
goto_functions.update();
368367
}
369368

370369
void full_slicer(

src/goto-instrument/goto_instrument_parse_options.cpp

+4-4
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

@@ -707,7 +708,6 @@ int goto_instrument_parse_optionst::doit()
707708
accelerate_functions(
708709
goto_model, get_message_handler(), cmdline.isset("z3"));
709710
remove_skip(goto_model);
710-
goto_model.goto_functions.update();
711711
}
712712

713713
if(cmdline.isset("horn-encoding"))

src/goto-instrument/model_argc_argv.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ bool model_argc_argv(
182182

183183
// update counters etc.
184184
remove_skip(start);
185-
start.compute_loop_numbers();
186-
goto_model.goto_functions.update();
187185

188186
return false;
189187
}

src/goto-instrument/reachability_slicer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ void reachability_slicert::slice(goto_functionst &goto_functions)
206206

207207
// remove the skips
208208
remove_skip(goto_functions);
209-
goto_functions.update();
210209
}
211210

212211
/// Perform reachability slicing on goto_model, with respect to the

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/goto_inline.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Author: Daniel Kroening, [email protected]
1919
#include <util/std_code.h>
2020
#include <util/std_expr.h>
2121

22-
#include "remove_skip.h"
2322
#include "goto_inline_class.h"
2423

2524
void goto_inline(

0 commit comments

Comments
 (0)