Skip to content

Commit 94e15b6

Browse files
author
Owen Jones
committed
Only update goto program if it was changed
1 parent 283c4f8 commit 94e15b6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

jbmc/src/java_bytecode/convert_java_nondet.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ Author: Reuben Thomas, [email protected]
2929
/// \param target: One of the steps in that goto program.
3030
/// \param symbol_table: The global symbol table.
3131
/// \param message_handler: Handles logging.
32-
/// \param max_nondet_array_length: Maximum size of new nondet arrays.
33-
/// \return The next instruction to process with this function.
34-
static goto_programt::targett insert_nondet_init_code(
32+
/// \param object_factory_parameters: Parameters for the generation of nondet
33+
/// objects.
34+
/// \return The next instruction to process with this function and a boolean
35+
/// indicating whether any changes were made to the goto program.
36+
static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
3537
goto_programt &goto_program,
3638
const goto_programt::targett &target,
3739
symbol_table_baset &symbol_table,
@@ -40,6 +42,7 @@ static goto_programt::targett insert_nondet_init_code(
4042
const irep_idt &mode)
4143
{
4244
const auto next_instr = std::next(target);
45+
bool changed = false;
4346

4447
// We only expect to find nondets in the rhs of an assignments or in return
4548
// statements
@@ -132,9 +135,11 @@ static goto_programt::targett insert_nondet_init_code(
132135
// Finally insert the dead instruction for aux_symbol after target
133136
goto_program.insert_after(target)->swap(
134137
aux_instructions.instructions.back());
138+
139+
changed = true;
135140
}
136141

137-
return next_instr;
142+
return std::make_pair(next_instr, changed);
138143
}
139144

140145
/// For each instruction in the goto program, checks if it is an assignment from
@@ -151,20 +156,27 @@ void convert_nondet(
151156
const object_factory_parameterst &object_factory_parameters,
152157
const irep_idt &mode)
153158
{
154-
for(auto instruction_iterator=goto_program.instructions.begin(),
155-
end=goto_program.instructions.end();
156-
instruction_iterator!=end;)
159+
bool changed = false;
160+
auto instruction_iterator = goto_program.instructions.begin();
161+
auto end = goto_program.instructions.end();
162+
163+
while(instruction_iterator != end)
157164
{
158-
instruction_iterator = insert_nondet_init_code(
165+
auto ret = insert_nondet_init_code(
159166
goto_program,
160167
instruction_iterator,
161168
symbol_table,
162169
message_handler,
163170
object_factory_parameters,
164171
mode);
172+
instruction_iterator = ret.first;
173+
changed |= ret.second;
165174
}
166175

167-
goto_program.update();
176+
if(changed)
177+
{
178+
goto_program.update();
179+
}
168180
}
169181

170182
void convert_nondet(

0 commit comments

Comments
 (0)