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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 23 additions & 9 deletions
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

Lines changed: 0 additions & 4 deletions
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

0 commit comments

Comments
 (0)