Skip to content

Commit 199d4cc

Browse files
author
Daniel Kroening
committed
prevent half-constructed GOTO instructions
1 parent 309d207 commit 199d4cc

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

jbmc/regression/jbmc/generic_class_bound1/test.desc

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Gn.class
33
--cover location
44
^EXIT=0$
55
^SIGNAL=0$
6-
.*file Gn.java line 6 function java::Gn.\<init\>:\(\)V bytecode-index 1 block 1: FAILED
7-
.*file Gn.java line 9 function java::Gn.foo1:\(LGn;\)V bytecode-index 1 block 1: FAILED
8-
.*file Gn.java line 10 function java::Gn.foo1:\(LGn;\)V bytecode-index 4 block 2: FAILED
9-
.*file Gn.java line 13 function java::Gn.main:\(\[Ljava/lang/String;\)V bytecode-index 2 block 2: SATISFIED
6+
.*file Gn.java line 6 function java::Gn.\<init\>:\(\)V bytecode-index 1 block .: FAILED
7+
.*file Gn.java line 9 function java::Gn.foo1:\(LGn;\)V bytecode-index 1 block .: FAILED
8+
.*file Gn.java line 10 function java::Gn.foo1:\(LGn;\)V bytecode-index 4 block .: FAILED
9+
.*file Gn.java line 13 function java::Gn.main:\(\[Ljava/lang/String;\)V bytecode-index 2 block .: SATISFIED
1010
--
1111
--
1212
This fails under symex-driven lazy loading because the FAILED blocks occur in functions that are unreachable

jbmc/regression/jbmc/reachability-slice/test2.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE symex-driven-lazy-loading-expected-failure
22
A.class
3-
--reachability-slice-fb --show-goto-functions --property 'java::A.foo:(I)V.coverage.3' --cover location
3+
--reachability-slice-fb --show-goto-functions --property 'java::A.foo:(I)V.coverage.4' --cover location
44
1001
55
1002
66
1003

jbmc/src/java_bytecode/remove_exceptions.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ void remove_exceptionst::add_exception_dispatch_sequence(
306306
// Jump to the universal handler or function end, as appropriate.
307307
// This will appear after the GOTO-based dynamic dispatch below
308308
goto_programt::targett default_dispatch=goto_program.insert_after(instr_it);
309-
default_dispatch->make_goto();
310-
default_dispatch->source_location=instr_it->source_location;
311-
default_dispatch->function=instr_it->function;
312309

313310
// find the symbol corresponding to the caught exceptions
314311
symbol_exprt exc_thrown =
@@ -356,7 +353,9 @@ void remove_exceptionst::add_exception_dispatch_sequence(
356353
}
357354
}
358355

359-
default_dispatch->set_target(default_target);
356+
default_dispatch->make_goto(default_target);
357+
default_dispatch->source_location=instr_it->source_location;
358+
default_dispatch->function=instr_it->function;
360359

361360
// add dead instructions
362361
for(const auto &local : locals)

src/goto-instrument/accelerate/accelerate.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,12 @@ void acceleratet::insert_looping_path(
212212
++loop_body;
213213

214214
goto_programt::targett jump=program.insert_before(loop_body);
215-
jump->make_goto();
216-
jump->guard=side_effect_expr_nondett(bool_typet());
217-
jump->targets.push_back(loop_body);
215+
jump->make_goto(loop_body, side_effect_expr_nondett(bool_typet()));
218216

219217
program.destructive_insert(loop_body, looping_path);
220218

221219
jump=program.insert_before(loop_body);
222-
jump->make_goto();
223-
jump->guard=true_exprt();
224-
jump->targets.push_back(back_jump);
220+
jump->make_goto(back_jump, true_exprt());
225221

226222
for(goto_programt::targett t=loop_header;
227223
t!=loop_body;

src/goto-instrument/branch.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void branch(
5656
t1->function=f_it->first;
5757

5858
goto_programt::targett t2=body.insert_after(t1);
59-
t2->make_goto();
60-
t2->targets=i_it->targets;
59+
t2->make_goto(i_it->get_target());
6160

6261
goto_programt::targett t3=body.insert_after(t2);
6362
t3->make_function_call(

src/goto-programs/goto_convert.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
138138
throw 0;
139139
}
140140

141+
i.type=GOTO;
141142
i.targets.clear();
142143
i.targets.push_back(l_it->second.first);
143144

@@ -1459,21 +1460,21 @@ void goto_convertt::convert_goto(
14591460
const codet &code,
14601461
goto_programt &dest)
14611462
{
1462-
goto_programt::targett t=dest.add_instruction();
1463-
t->make_goto();
1463+
// this instruction will turn into a goto during post-processing
1464+
goto_programt::targett t=dest.add_instruction(NO_INSTRUCTION_TYPE);
14641465
t->source_location=code.source_location();
14651466
t->code=code;
14661467

1467-
// remember it to do target later
1468+
// remember it to do the target later
14681469
targets.gotos.push_back(std::make_pair(t, targets.destructor_stack));
14691470
}
14701471

14711472
void goto_convertt::convert_gcc_computed_goto(
14721473
const codet &code,
14731474
goto_programt &dest)
14741475
{
1475-
goto_programt::targett t=dest.add_instruction();
1476-
t->make_skip();
1476+
// this instruction will turn into OTHER during post-processing
1477+
goto_programt::targett t=dest.add_instruction(NO_INSTRUCTION_TYPE);
14771478
t->source_location=code.source_location();
14781479
t->code=code;
14791480

src/goto-programs/goto_program.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ class goto_programt
237237
code.make_nil();
238238
}
239239

240-
void make_goto() { clear(GOTO); }
241240
void make_return() { clear(RETURN); }
242241
void make_skip() { clear(SKIP); }
243242
void make_location(const source_locationt &l)
@@ -256,7 +255,7 @@ class goto_programt
256255

257256
void make_goto(targett _target)
258257
{
259-
make_goto();
258+
clear(GOTO);
260259
targets.push_back(_target);
261260
}
262261

0 commit comments

Comments
 (0)