Skip to content

Commit d117475

Browse files
authored
Merge pull request #860 from reuk/nondet-memory-fix
Remove 'erase' in replace_java_nondet.cpp, fixes #850
2 parents f5aa612 + d15d842 commit d117475

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/goto-programs/convert_nondet.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Reuben Thomas, [email protected]
99
#include "goto-programs/convert_nondet.h"
1010
#include "goto-programs/goto_convert.h"
1111
#include "goto-programs/goto_model.h"
12+
#include "goto-programs/remove_skip.h"
1213

1314
#include "java_bytecode/java_object_factory.h" // gen_nondet_init
1415

@@ -34,9 +35,9 @@ Function: insert_nondet_init_code
3435
3536
\*******************************************************************/
3637

37-
static goto_programt::const_targett insert_nondet_init_code(
38+
static goto_programt::targett insert_nondet_init_code(
3839
goto_programt &goto_program,
39-
const goto_programt::const_targett &target,
40+
const goto_programt::targett &target,
4041
symbol_tablet &symbol_table,
4142
message_handlert &message_handler,
4243
size_t max_nondet_array_length)
@@ -82,7 +83,7 @@ static goto_programt::const_targett insert_nondet_init_code(
8283
const auto source_loc=target->source_location;
8384

8485
// Erase the nondet assignment
85-
const auto after_erased=goto_program.instructions.erase(target);
86+
target->make_skip();
8687

8788
// Generate nondet init code
8889
code_blockt init_code;
@@ -101,10 +102,10 @@ static goto_programt::const_targett insert_nondet_init_code(
101102
goto_convert(init_code, symbol_table, new_instructions, message_handler);
102103

103104
// Insert the new instructions into the instruction list
104-
goto_program.destructive_insert(after_erased, new_instructions);
105+
goto_program.destructive_insert(next_instr, new_instructions);
105106
goto_program.update();
106107

107-
return after_erased;
108+
return next_instr;
108109
}
109110

110111
/*******************************************************************\
@@ -129,9 +130,9 @@ static void convert_nondet(
129130
message_handlert &message_handler,
130131
size_t max_nondet_array_length)
131132
{
132-
for(auto instruction_iterator=goto_program.instructions.cbegin(),
133-
end=goto_program.instructions.cend();
134-
instruction_iterator!=end;)
133+
for(auto instruction_iterator=goto_program.instructions.begin(),
134+
end=goto_program.instructions.end();
135+
instruction_iterator!=end;)
135136
{
136137
instruction_iterator=insert_nondet_init_code(
137138
goto_program,
@@ -160,4 +161,6 @@ void convert_nondet(
160161
}
161162

162163
goto_functions.compute_location_numbers();
164+
165+
remove_skip(goto_functions);
163166
}

src/goto-programs/replace_java_nondet.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Reuben Thomas, [email protected]
99
#include "goto-programs/replace_java_nondet.h"
1010
#include "goto-programs/goto_convert.h"
1111
#include "goto-programs/goto_model.h"
12+
#include "goto-programs/remove_skip.h"
1213

1314
#include "util/irep_ids.h"
1415

@@ -215,9 +216,9 @@ Function: check_and_replace_target
215216
216217
\*******************************************************************/
217218

218-
static goto_programt::const_targett check_and_replace_target(
219+
static goto_programt::targett check_and_replace_target(
219220
goto_programt &goto_program,
220-
const goto_programt::const_targett &target)
221+
const goto_programt::targett &target)
221222
{
222223
// Check whether this is a nondet library method, and return if not
223224
const auto instr_info=get_nondet_instruction_info(target);
@@ -241,7 +242,7 @@ static goto_programt::const_targett check_and_replace_target(
241242
to_symbol_expr(next_instr_assign_lhs).get_identifier();
242243

243244
auto &instructions=goto_program.instructions;
244-
const auto end=instructions.cend();
245+
const auto end=instructions.end();
245246

246247
// Look for an instruction where this name is on the RHS of an assignment
247248
const auto matching_assignment=std::find_if(
@@ -263,10 +264,15 @@ static goto_programt::const_targett check_and_replace_target(
263264
const auto after_matching_assignment=std::next(matching_assignment);
264265
assert(after_matching_assignment!=end);
265266

266-
const auto after_erased=goto_program.instructions.erase(
267-
target, after_matching_assignment);
267+
std::for_each(
268+
target,
269+
after_matching_assignment,
270+
[](goto_programt::instructiont &instr)
271+
{
272+
instr.make_skip();
273+
});
268274

269-
const auto inserted=goto_program.insert_before(after_erased);
275+
const auto inserted=goto_program.insert_before(after_matching_assignment);
270276
inserted->make_assignment();
271277
side_effect_expr_nondett inserted_expr(nondet_var.type());
272278
inserted_expr.set_nullable(
@@ -278,7 +284,7 @@ static goto_programt::const_targett check_and_replace_target(
278284

279285
goto_program.update();
280286

281-
return after_erased;
287+
return after_matching_assignment;
282288
}
283289

284290
/*******************************************************************\
@@ -297,8 +303,8 @@ Function: replace_java_nondet
297303

298304
static void replace_java_nondet(goto_programt &goto_program)
299305
{
300-
for(auto instruction_iterator=goto_program.instructions.cbegin(),
301-
end=goto_program.instructions.cend();
306+
for(auto instruction_iterator=goto_program.instructions.begin(),
307+
end=goto_program.instructions.end();
302308
instruction_iterator!=end;)
303309
{
304310
instruction_iterator=check_and_replace_target(
@@ -315,5 +321,8 @@ void replace_java_nondet(goto_functionst &goto_functions)
315321
{
316322
replace_java_nondet(goto_program.second.body);
317323
}
324+
318325
goto_functions.compute_location_numbers();
326+
327+
remove_skip(goto_functions);
319328
}

0 commit comments

Comments
 (0)