Skip to content

Commit 44273a3

Browse files
authored
Merge pull request #6853 from diffblue/protect_guard
protect goto_instructiont::guard
2 parents 1cfc93f + 54b88f6 commit 44273a3

18 files changed

+89
-69
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void remove_exceptionst::add_exception_dispatch_sequence(
368368
struct_tag_typet type(stack_catch[i][j].first);
369369

370370
java_instanceof_exprt check(exc_thrown, type);
371-
t_exc->guard=check;
371+
t_exc->condition_nonconst() = check;
372372

373373
if(remove_added_instanceof)
374374
{

jbmc/src/java_bytecode/remove_instanceof.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ bool remove_instanceoft::lower_instanceof(
243243
{
244244
if(
245245
target->is_target() &&
246-
(contains_instanceof(target->code()) || contains_instanceof(target->guard)))
246+
(contains_instanceof(target->code()) ||
247+
(target->has_condition() && contains_instanceof(target->condition()))))
247248
{
248249
// If this is a branch target, add a skip beforehand so we can splice new
249250
// GOTO programs before the target instruction without inserting into the
@@ -256,8 +257,12 @@ bool remove_instanceoft::lower_instanceof(
256257

257258
return lower_instanceof(
258259
function_identifier, target->code_nonconst(), goto_program, target) |
259-
lower_instanceof(
260-
function_identifier, target->guard, goto_program, target);
260+
(target->has_condition() ? lower_instanceof(
261+
function_identifier,
262+
target->condition_nonconst(),
263+
goto_program,
264+
target)
265+
: false);
261266
}
262267

263268
/// Replace every instanceof in the passed function body with an explicit

jbmc/unit/java_bytecode/goto-programs/remove_virtual_functions_without_fallback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static bool is_call_to(
7171

7272
static bool is_assume_false(goto_programt::const_targett inst)
7373
{
74-
return inst->is_assume() && inst->guard.is_false();
74+
return inst->is_assume() && inst->condition().is_false();
7575
}
7676

7777
/// Interpret `program`, resolving classid comparisons assuming any actual
@@ -90,7 +90,7 @@ static goto_programt::const_targett interpret_classid_comparison(
9090
{
9191
if(pc->type() == GOTO)
9292
{
93-
exprt guard = pc->guard;
93+
exprt guard = pc->condition();
9494
guard = resolve_classid_test(guard, actual_class_id, ns);
9595
if(guard.is_true())
9696
{

jbmc/unit/java_bytecode/java_bytecode_instrument/virtual_call_null_checks.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,20 @@ SCENARIO(
9292
}
9393
}
9494

95-
for(auto it = instrit->guard.depth_begin(),
96-
itend = instrit->guard.depth_end();
97-
it != itend; ++it)
95+
if(instrit->has_condition())
9896
{
99-
if(it->id() == ID_dereference)
97+
const auto &condition = instrit->condition();
98+
99+
for(auto it = condition.depth_begin(),
100+
itend = condition.depth_end();
101+
it != itend;
102+
++it)
100103
{
101-
const auto &deref = to_dereference_expr(*it);
102-
REQUIRE(
103-
safe_pointers.is_safe_dereference(deref, instrit));
104+
if(it->id() == ID_dereference)
105+
{
106+
const auto &deref = to_dereference_expr(*it);
107+
REQUIRE(safe_pointers.is_safe_dereference(deref, instrit));
108+
}
104109
}
105110
}
106111
}

jbmc/unit/java_bytecode/java_virtual_functions/virtual_functions.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ SCENARIO(
7171
// branching for class C and one for class D or O.
7272
if(instruction.type() == goto_program_instruction_typet::GOTO)
7373
{
74-
if(instruction.guard.id() == ID_equal)
74+
if(instruction.condition().id() == ID_equal)
7575
{
7676
THEN("Class C should call its specific method")
7777
{
78-
const equal_exprt &eq_expr = to_equal_expr(instruction.guard);
78+
const equal_exprt &eq_expr =
79+
to_equal_expr(instruction.condition());
7980
check_function_call(
8081
eq_expr,
8182
"java::C",
@@ -84,11 +85,12 @@ SCENARIO(
8485
}
8586
}
8687

87-
else if(instruction.guard.id() == ID_or)
88+
else if(instruction.condition().id() == ID_or)
8889
{
8990
THEN("Classes D and O should both call O.toString()")
9091
{
91-
const or_exprt &disjunction = to_or_expr(instruction.guard);
92+
const or_exprt &disjunction =
93+
to_or_expr(instruction.condition());
9294
REQUIRE(
9395
(disjunction.op0().id() == ID_equal &&
9496
disjunction.op1().id() == ID_equal));

src/analyses/interval_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void instrument_intervals(
5050
{
5151
// we follow a branch, instrument
5252
}
53-
else if(previous->is_function_call() && !previous->guard.is_true())
53+
else if(previous->is_function_call())
5454
{
5555
// we follow a function call, instrument
5656
}

src/analyses/variable-sensitivity/variable_sensitivity_domain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ void variable_sensitivity_domaint::transform(
7979
if(to == from->get_target())
8080
{
8181
// The AI is exploring the branch where the jump is taken
82-
assume(instruction.guard, ns);
82+
assume(instruction.condition(), ns);
8383
}
8484
else
8585
{
8686
// Exploring the path where the jump is not taken - therefore assume
8787
// the condition is false
88-
assume(not_exprt(instruction.guard), ns);
88+
assume(not_exprt(instruction.condition()), ns);
8989
}
9090
}
9191
// ignore jumps to the next line, we can assume nothing
@@ -94,7 +94,7 @@ void variable_sensitivity_domaint::transform(
9494
break;
9595

9696
case ASSUME:
97-
assume(instruction.guard, ns);
97+
assume(instruction.condition(), ns);
9898
break;
9999

100100
case FUNCTION_CALL:

src/goto-cc/linker_script_merge.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ int linker_script_merget::pointerize_linker_defined_symbols(
258258
goto_programt &program=gf.second.body;
259259
for(auto &instruction : program.instructions)
260260
{
261-
for(exprt *insts : std::list<exprt *>(
262-
{&(instruction.code_nonconst()), &(instruction.guard)}))
261+
std::list<exprt *> expressions = {&instruction.code_nonconst()};
262+
if(instruction.has_condition())
263+
expressions.push_back(&instruction.condition_nonconst());
264+
265+
for(exprt *insts : expressions)
263266
{
264267
std::list<symbol_exprt> to_pointerize;
265268
symbols_to_pointerize(linker_values, *insts, to_pointerize);

src/goto-checker/symex_coverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void goto_program_coverage_recordt::compute_coverage_lines(
214214
it->is_end_function())
215215
continue;
216216

217-
const bool is_branch = it->is_goto() && !it->guard.is_constant();
217+
const bool is_branch = it->is_goto() && !it->condition().is_constant();
218218

219219
unsigned l =
220220
safe_string2unsigned(id2string(it->source_location().get_line()));

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void memory_snapshot_harness_generatort::add_init_section(
165165
auto ins_it1 = goto_program.insert_before(
166166
start_it,
167167
goto_programt::make_goto(goto_program.const_cast_target(start_it)));
168-
ins_it1->guard = func_init_done_var;
168+
ins_it1->condition_nonconst() = func_init_done_var;
169169

170170
auto ins_it2 = goto_program.insert_after(
171171
ins_it1,

0 commit comments

Comments
 (0)