30
30
// / \param symbol_table: The global symbol table.
31
31
// / \param message_handler: Handles logging.
32
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 (
33
+ // / \return The next instruction to process with this function and a boolean
34
+ // / indicating whether any changes were made to the goto program.
35
+ static std::pair<goto_programt::targett, bool > insert_nondet_init_code (
35
36
goto_programt &goto_program,
36
37
const goto_programt::targett &target,
37
38
symbol_table_baset &symbol_table,
@@ -40,6 +41,7 @@ static goto_programt::targett insert_nondet_init_code(
40
41
const irep_idt &mode)
41
42
{
42
43
const auto next_instr = std::next (target);
44
+ bool changed = false ;
43
45
44
46
// We only expect to find nondets in the rhs of an assignments or in return
45
47
// statements
@@ -132,9 +134,11 @@ static goto_programt::targett insert_nondet_init_code(
132
134
// Finally insert the dead instruction for aux_symbol after target
133
135
goto_program.insert_after (target)->swap (
134
136
aux_instructions.instructions .back ());
137
+
138
+ changed = true ;
135
139
}
136
140
137
- return next_instr;
141
+ return std::make_pair ( next_instr, changed) ;
138
142
}
139
143
140
144
// / For each instruction in the goto program, checks if it is an assignment from
@@ -151,20 +155,27 @@ void convert_nondet(
151
155
const object_factory_parameterst &object_factory_parameters,
152
156
const irep_idt &mode)
153
157
{
154
- for (auto instruction_iterator=goto_program.instructions .begin (),
155
- end=goto_program.instructions .end ();
156
- instruction_iterator!=end;)
158
+ bool changed = false ;
159
+ auto instruction_iterator = goto_program.instructions .begin ();
160
+ auto end = goto_program.instructions .end ();
161
+
162
+ while (instruction_iterator != end)
157
163
{
158
- instruction_iterator = insert_nondet_init_code (
164
+ auto ret = insert_nondet_init_code (
159
165
goto_program,
160
166
instruction_iterator,
161
167
symbol_table,
162
168
message_handler,
163
169
object_factory_parameters,
164
170
mode);
171
+ instruction_iterator = ret.first ;
172
+ changed |= ret.second ;
165
173
}
166
174
167
- goto_program.update ();
175
+ if (changed)
176
+ {
177
+ goto_program.update ();
178
+ }
168
179
}
169
180
170
181
void convert_nondet (
0 commit comments