@@ -90,9 +90,16 @@ static goto_programt::targett insert_nondet_init_code(
90
90
code_declt decl (aux_symbol_expr);
91
91
decl.add_source_location () = source_loc;
92
92
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
+
93
101
// Generate nondet init code
94
102
code_blockt init_code;
95
- init_code.add (decl);
96
103
97
104
gen_nondet_init (
98
105
aux_symbol_expr,
@@ -105,16 +112,27 @@ static goto_programt::targett insert_nondet_init_code(
105
112
update_in_placet::NO_UPDATE_IN_PLACE);
106
113
107
114
// Convert this code into goto instructions
108
- goto_programt new_instructions ;
115
+ goto_programt nondet_init_instructions ;
109
116
goto_convert (
110
- init_code, symbol_table, new_instructions , message_handler, mode);
117
+ init_code, symbol_table, nondet_init_instructions , message_handler, mode);
111
118
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);
115
127
116
- // Replace op with aux symbol
128
+ // Replace op with aux symbol in target
117
129
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 ();
118
136
}
119
137
120
138
return next_instr;
0 commit comments