Skip to content

Commit 70d3fea

Browse files
author
Owen Jones
committed
Try 2
1 parent c31abd0 commit 70d3fea

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

jbmc/src/java_bytecode/convert_java_nondet.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ static goto_programt::targett insert_nondet_init_code(
9090
code_declt decl(aux_symbol_expr);
9191
decl.add_source_location() = source_loc;
9292

93+
// Create goto instructions for declaring and deading aux_symbol
94+
goto_programt aux_instructions;
95+
code_blockt aux_block;
96+
aux_block.move(decl);
97+
goto_convert(
98+
aux_block, symbol_table, aux_instructions, message_handler, mode);
99+
CHECK_RETURN(aux_instructions.instructions.size() == 2);
100+
93101
// Generate nondet init code
94102
code_blockt init_code;
95-
init_code.add(decl);
96103

97104
gen_nondet_init(
98105
aux_symbol_expr,
@@ -105,16 +112,27 @@ static goto_programt::targett insert_nondet_init_code(
105112
update_in_placet::NO_UPDATE_IN_PLACE);
106113

107114
// Convert this code into goto instructions
108-
goto_programt new_instructions;
115+
goto_programt nondet_init_instructions;
109116
goto_convert(
110-
init_code, symbol_table, new_instructions, message_handler, mode);
117+
init_code, symbol_table, nondet_init_instructions, message_handler, mode);
111118

112-
// Insert the new instructions into the instruction list before target
113-
goto_program.destructive_insert(target, new_instructions);
114-
goto_program.update();
119+
// First insert the declaration of aux_symbol at the front of
120+
// nondet_init_instructions
121+
goto_program.insert_before_swap(
122+
nondet_init_instructions.instructions.begin(),
123+
aux_instructions.instructions.front());
124+
125+
// Insert nondet_init_instructions into the instruction list before target
126+
goto_program.destructive_insert(target, nondet_init_instructions);
115127

116-
// Replace op with aux symbol
128+
// Replace op with aux symbol in target
117129
op = aux_symbol_expr;
130+
131+
// Finally insert the dead instruction for aux_symbol after target
132+
goto_program.insert_after(target)->swap(
133+
aux_instructions.instructions.back());
134+
135+
goto_program.update();
118136
}
119137

120138
return next_instr;

0 commit comments

Comments
 (0)