Skip to content

Commit 2c63234

Browse files
author
Daniel Kroening
committed
avoid goto_programt::insert_before and _after without instruction
Instead use the variant that takes the instruction to be constructed as parameter, thereby avoiding duplicate assignment.
1 parent 68b192a commit 2c63234

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

src/goto-instrument/accelerate/accelerate.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,19 @@ void acceleratet::make_overflow_loc(
258258
loop.insert(added.begin(), added.end());
259259
}
260260

261-
goto_programt::targett t=program.insert_after(loop_header);
262-
*t =
263-
goto_programt::make_assignment(code_assignt(overflow_var, false_exprt()));
261+
goto_programt::targett t = program.insert_after(
262+
loop_header,
263+
goto_programt::make_assignment(code_assignt(overflow_var, false_exprt())));
264264
t->swap(*loop_header);
265265
loop.insert(t);
266266
overflow_locs[loop_header].push_back(t);
267267

268-
goto_programt::instructiont s(SKIP);
269-
overflow_loc=program.insert_after(loop_end);
270-
*overflow_loc=s;
268+
overflow_loc = program.insert_after(loop_end, goto_programt::make_skip());
271269
overflow_loc->swap(*loop_end);
272270
loop.insert(overflow_loc);
273271

274-
goto_programt::instructiont g =
275-
goto_programt::make_goto(overflow_loc, not_exprt(overflow_var));
276-
277-
goto_programt::targett t2=program.insert_after(loop_end);
278-
*t2=g;
272+
goto_programt::targett t2 = program.insert_after(
273+
loop_end, goto_programt::make_goto(overflow_loc, not_exprt(overflow_var)));
279274
t2->swap(*loop_end);
280275
overflow_locs[overflow_loc].push_back(t2);
281276
loop.insert(t2);

src/goto-instrument/accelerate/overflow_instrumenter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,9 @@ void overflow_instrumentert::accumulate_overflow(
286286
const exprt &expr,
287287
goto_programt::targetst &added)
288288
{
289-
goto_programt::instructiont a(ASSIGN);
290-
a.code=code_assignt(overflow_var, or_exprt(overflow_var, expr));
291-
goto_programt::targett assignment=program.insert_after(t);
292-
*assignment=a;
289+
goto_programt::targett assignment = program.insert_after(
290+
t,
291+
goto_programt::make_assignment(overflow_var, or_exprt(overflow_var, expr)));
293292
assignment->swap(*t);
294293

295294
added.push_back(assignment);

src/goto-instrument/race_check.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ void w_guardst::add_initialization(goto_programt &goto_program) const
9999
{
100100
exprt symbol=ns.lookup(*it).symbol_expr();
101101

102-
t=goto_program.insert_before(t);
103-
t->type=ASSIGN;
104-
t->code=code_assignt(symbol, false_exprt());
102+
t = goto_program.insert_before(
103+
t, goto_programt::make_assignment(symbol, false_exprt()));
105104

106105
t++;
107106
}
@@ -199,14 +198,12 @@ static void race_check(
199198
if(!is_shared(ns, e_it->second.symbol_expr))
200199
continue;
201200

202-
goto_programt::targett t=goto_program.insert_before(i_it);
203-
204-
t->type=ASSIGN;
205-
t->code=code_assignt(
206-
w_guards.get_w_guard_expr(e_it->second),
207-
e_it->second.guard);
208-
209-
t->source_location=original_instruction.source_location;
201+
goto_programt::targett t = goto_program.insert_before(
202+
i_it,
203+
goto_programt::make_assignment(
204+
w_guards.get_w_guard_expr(e_it->second),
205+
e_it->second.guard,
206+
original_instruction.source_location));
210207
i_it=++t;
211208
}
212209

@@ -223,15 +220,13 @@ static void race_check(
223220
if(!is_shared(ns, e_it->second.symbol_expr))
224221
continue;
225222

226-
goto_programt::targett t=goto_program.insert_before(i_it);
227-
228-
t->type=ASSIGN;
229-
t->code=code_assignt(
230-
w_guards.get_w_guard_expr(e_it->second),
231-
false_exprt());
232-
233-
t->source_location=original_instruction.source_location;
234-
i_it=++t;
223+
goto_programt::targett t = goto_program.insert_before(
224+
i_it,
225+
goto_programt::make_assignment(
226+
w_guards.get_w_guard_expr(e_it->second),
227+
false_exprt(),
228+
original_instruction.source_location));
229+
i_it = std::next(t);
235230
}
236231

237232
// now add assertions for what is read and written

src/goto-programs/goto_convert.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,9 @@ void goto_convertt::finish_computed_gotos(goto_programt &goto_program)
216216

217217
const equal_exprt guard(pointer, address_of_exprt(label_expr));
218218

219-
goto_programt::targett t=
220-
goto_program.insert_after(g_it);
221-
222-
*t =
223-
goto_programt::make_goto(label.second.first, guard, i.source_location);
219+
goto_program.insert_after(
220+
g_it,
221+
goto_programt::make_goto(label.second.first, guard, i.source_location));
224222
}
225223
}
226224

0 commit comments

Comments
 (0)