Skip to content

Commit e91d3e1

Browse files
author
Daniel Kroening
committed
use goto_progamt::make_X API
This prevents partial construction of instructiont.
1 parent 606a83a commit e91d3e1

File tree

69 files changed

+581
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+581
-694
lines changed

jbmc/src/java_bytecode/convert_java_nondet.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
124124

125125
// Insert an instruction declaring `aux_symbol` before `target`, being
126126
// careful to preserve jumps to `target`
127-
goto_programt::instructiont decl_aux_symbol;
128-
decl_aux_symbol.make_decl(code_declt(aux_symbol_expr));
129-
decl_aux_symbol.source_location = source_loc;
127+
goto_programt::instructiont decl_aux_symbol =
128+
goto_programt::make_decl(code_declt(aux_symbol_expr), source_loc);
130129
goto_program.insert_before_swap(target, decl_aux_symbol);
131130

132131
// Keep track of the new location of the instruction containing op.
@@ -142,10 +141,8 @@ static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
142141
mode);
143142
goto_program.destructive_insert(target2, gen_nondet_init_instructions);
144143

145-
goto_programt::targett dead_aux_symbol = goto_program.insert_after(target2);
146-
dead_aux_symbol->make_dead();
147-
dead_aux_symbol->code = code_deadt(aux_symbol_expr);
148-
dead_aux_symbol->source_location = source_loc;
144+
goto_program.insert_after(
145+
target2, goto_programt::make_dead(aux_symbol_expr, source_loc));
149146

150147
// In theory target could have more than one operand which should be
151148
// replaced by convert_nondet, so we return target2 so that it

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,23 @@ void remove_exceptionst::instrument_exception_handler(
233233
null_pointer_exprt null_voidptr((pointer_type(java_void_type())));
234234

235235
// add the assignment @inflight_exception = NULL
236-
goto_programt::targett t_null=goto_program.insert_after(instr_it);
237-
t_null->make_assignment();
238-
t_null->source_location=instr_it->source_location;
239-
t_null->code=code_assignt(
240-
thrown_global_symbol,
241-
null_voidptr);
236+
goto_program.insert_after(
237+
instr_it,
238+
goto_programt::make_assignment(
239+
code_assignt(thrown_global_symbol, null_voidptr),
240+
instr_it->source_location));
242241

243242
// add the assignment exc = @inflight_exception (before the null assignment)
244-
goto_programt::targett t_exc=goto_program.insert_after(instr_it);
245-
t_exc->make_assignment();
246-
t_exc->source_location=instr_it->source_location;
247-
t_exc->code=code_assignt(
248-
thrown_exception_local,
249-
typecast_exprt(thrown_global_symbol, thrown_exception_local.type()));
243+
goto_program.insert_after(
244+
instr_it,
245+
goto_programt::make_assignment(
246+
code_assignt(
247+
thrown_exception_local,
248+
typecast_exprt(thrown_global_symbol, thrown_exception_local.type())),
249+
instr_it->source_location));
250250
}
251-
instr_it->make_skip();
251+
252+
instr_it->turn_into_skip();
252253
}
253254

254255
/// Find the innermost universal exception handler for the current
@@ -349,9 +350,10 @@ void remove_exceptionst::add_exception_dispatch_sequence(
349350
if(!stack_catch[i][j].first.empty())
350351
{
351352
// Normal exception handler, make an instanceof check.
352-
goto_programt::targett t_exc=goto_program.insert_after(instr_it);
353-
t_exc->make_goto(new_state_pc, true_exprt());
354-
t_exc->source_location=instr_it->source_location;
353+
goto_programt::targett t_exc = goto_program.insert_after(
354+
instr_it,
355+
goto_programt::make_goto(
356+
new_state_pc, true_exprt(), instr_it->source_location));
355357

356358
// use instanceof to check that this is the correct handler
357359
struct_tag_typet type(stack_catch[i][j].first);
@@ -374,16 +376,14 @@ void remove_exceptionst::add_exception_dispatch_sequence(
374376
}
375377
}
376378

377-
default_dispatch->make_goto(default_target, true_exprt());
378-
default_dispatch->source_location=instr_it->source_location;
379+
*default_dispatch = goto_programt::make_goto(
380+
default_target, true_exprt(), instr_it->source_location);
379381

380382
// add dead instructions
381383
for(const auto &local : locals)
382384
{
383-
goto_programt::targett t_dead=goto_program.insert_after(instr_it);
384-
t_dead->make_dead();
385-
t_dead->code=code_deadt(local);
386-
t_dead->source_location=instr_it->source_location;
385+
goto_program.insert_after(
386+
instr_it, goto_programt::make_dead(local, instr_it->source_location));
387387
}
388388
}
389389

@@ -451,18 +451,22 @@ bool remove_exceptionst::instrument_function_call(
451451
{
452452
// Function is annotated must-not-throw, but we can't prove that here.
453453
// Insert an ASSUME(@inflight_exception == null):
454-
goto_programt::targett assume_null = goto_program.insert_after(instr_it);
455-
assume_null->make_assumption(no_exception_currently_in_flight);
454+
goto_program.insert_after(
455+
instr_it,
456+
goto_programt::make_assumption(no_exception_currently_in_flight));
456457
}
457458
else
458459
{
459460
add_exception_dispatch_sequence(
460461
function_identifier, goto_program, instr_it, stack_catch, locals);
461462

462463
// add a null check (so that instanceof can be applied)
463-
goto_programt::targett t_null=goto_program.insert_after(instr_it);
464-
t_null->make_goto(next_it, no_exception_currently_in_flight);
465-
t_null->source_location=instr_it->source_location;
464+
goto_program.insert_after(
465+
instr_it,
466+
goto_programt::make_goto(
467+
next_it,
468+
no_exception_currently_in_flight,
469+
instr_it->source_location));
466470
}
467471

468472
return true;
@@ -566,7 +570,8 @@ void remove_exceptionst::instrument_exceptions(
566570
false,
567571
"CATCH opcode should be one of push-catch, pop-catch, landingpad");
568572
}
569-
instr_it->make_skip();
573+
574+
instr_it->turn_into_skip();
570575
did_something = true;
571576
}
572577
else if(instr_it->type==THROW)

jbmc/src/java_bytecode/remove_instanceof.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ bool remove_instanceoft::lower_instanceof(
211211
// GOTO programs before the target instruction without inserting into the
212212
// wrong basic block.
213213
goto_program.insert_before_swap(target);
214-
target->make_skip();
214+
*target = goto_programt::make_skip();
215215
// Actually alter the now-moved instruction:
216216
++target;
217217
}

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,19 @@ goto_programt::targett remove_java_newt::lower_java_new(
9494
malloc_expr.copy_to_operands(object_size);
9595
// could use true and get rid of the code below
9696
malloc_expr.copy_to_operands(false_exprt());
97-
target->make_assignment(code_assignt(lhs, malloc_expr));
98-
target->source_location = location;
97+
*target =
98+
goto_programt::make_assignment(code_assignt(lhs, malloc_expr), location);
9999

100100
// zero-initialize the object
101101
dereference_exprt deref(lhs, object_type);
102102
auto zero_object = zero_initializer(object_type, location, ns);
103103
CHECK_RETURN(zero_object.has_value());
104104
set_class_identifier(
105105
to_struct_expr(*zero_object), ns, to_struct_tag_type(object_type));
106-
goto_programt::targett t_i = dest.insert_after(target);
107-
t_i->make_assignment(code_assignt(deref, *zero_object));
108-
t_i->source_location = location;
109-
110-
return t_i;
106+
return dest.insert_after(
107+
target,
108+
goto_programt::make_assignment(
109+
code_assignt(deref, *zero_object), location));
111110
}
112111

113112
/// Replaces the instruction `lhs = new java_array_type` by
@@ -148,8 +147,8 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
148147
// code use true and get rid of the code below
149148
malloc_expr.copy_to_operands(false_exprt());
150149

151-
target->make_assignment(code_assignt(lhs, malloc_expr));
152-
target->source_location = location;
150+
*target =
151+
goto_programt::make_assignment(code_assignt(lhs, malloc_expr), location);
153152
goto_programt::targett next = std::next(target);
154153

155154
const struct_typet &struct_type = to_struct_type(ns.follow(object_type));
@@ -165,18 +164,19 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
165164
CHECK_RETURN(zero_object.has_value());
166165
set_class_identifier(
167166
to_struct_expr(*zero_object), ns, to_struct_tag_type(object_type));
168-
goto_programt::targett t_i = dest.insert_before(next);
169-
t_i->make_assignment(code_assignt(deref, *zero_object));
170-
t_i->source_location = location;
167+
dest.insert_before(
168+
next,
169+
goto_programt::make_assignment(
170+
code_assignt(deref, *zero_object), location));
171171

172172
// if it's an array, we need to set the length field
173173
member_exprt length(
174174
deref,
175175
struct_type.components()[1].get_name(),
176176
struct_type.components()[1].type());
177-
goto_programt::targett t_s = dest.insert_before(next);
178-
t_s->make_assignment(code_assignt(length, rhs.op0()));
179-
t_s->source_location = location;
177+
dest.insert_before(
178+
next,
179+
goto_programt::make_assignment(code_assignt(length, rhs.op0()), location));
180180

181181
// we also need to allocate space for the data
182182
member_exprt data(
@@ -221,20 +221,19 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
221221
.symbol_expr();
222222
code_declt array_decl(new_array_data_symbol);
223223
array_decl.add_source_location() = location;
224-
goto_programt::targett t_array_decl = dest.insert_before(next);
225-
t_array_decl->make_decl(array_decl);
226-
t_array_decl->source_location = location;
227-
goto_programt::targett t_p2 = dest.insert_before(next);
228-
t_p2->make_assignment(
229-
code_assignt(new_array_data_symbol, data_java_new_expr));
230-
t_p2->source_location = location;
231-
232-
goto_programt::targett t_p = dest.insert_before(next);
224+
dest.insert_before(next, goto_programt::make_decl(array_decl, location));
225+
dest.insert_before(
226+
next,
227+
goto_programt::make_assignment(
228+
code_assignt(new_array_data_symbol, data_java_new_expr), location));
229+
233230
exprt cast_java_new = new_array_data_symbol;
234231
if(cast_java_new.type() != data.type())
235232
cast_java_new = typecast_exprt(cast_java_new, data.type());
236-
t_p->make_assignment(code_assignt(data, cast_java_new));
237-
t_p->source_location = location;
233+
dest.insert_before(
234+
next,
235+
goto_programt::make_assignment(
236+
code_assignt(data, cast_java_new), location));
238237

239238
// zero-initialize the data
240239
if(!rhs.get_bool(ID_skip_initialize))
@@ -244,9 +243,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
244243
CHECK_RETURN(zero_element.has_value());
245244
codet array_set(ID_array_set);
246245
array_set.copy_to_operands(new_array_data_symbol, *zero_element);
247-
goto_programt::targett t_d = dest.insert_before(next);
248-
t_d->make_other(array_set);
249-
t_d->source_location = location;
246+
dest.insert_before(next, goto_programt::make_other(array_set, location));
250247
}
251248

252249
// multi-dimensional?
@@ -265,9 +262,8 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
265262
.symbol_expr();
266263
code_declt decl(tmp_i);
267264
decl.add_source_location() = location;
268-
goto_programt::targett t_decl = tmp.insert_before(tmp.instructions.begin());
269-
t_decl->make_decl(decl);
270-
t_decl->source_location = location;
265+
tmp.insert_before(
266+
tmp.instructions.begin(), goto_programt::make_decl(decl, location));
271267

272268
side_effect_exprt sub_java_new = rhs;
273269
sub_java_new.operands().erase(sub_java_new.operands().begin());

jbmc/src/java_bytecode/replace_java_nondet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static goto_programt::targett check_and_replace_target(
271271

272272
std::for_each(
273273
target, target_instruction, [](goto_programt::instructiont &instr) {
274-
instr.make_skip();
274+
instr.turn_into_skip();
275275
});
276276

277277
if(target_instruction->is_return())

src/analyses/escape_analysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ void escape_analysist::insert_cleanup(
427427
code.arguments().push_back(arg);
428428
}
429429

430-
location->make_function_call(code);
431-
location->source_location=source_location;
430+
*location = goto_programt::make_function_call(code, source_location);
432431
}
433432
}
434433

src/analyses/goto_check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,15 +1801,15 @@ void goto_checkt::goto_check(
18011801
i.source_location.get_property_class()!="error label") ||
18021802
(!is_user_provided && !enable_built_in_assertions))
18031803
{
1804-
i.make_skip();
1804+
i.turn_into_skip();
18051805
did_something = true;
18061806
}
18071807
}
18081808
else if(i.is_assume())
18091809
{
18101810
if(!enable_assumptions)
18111811
{
1812-
i.make_skip();
1812+
i.turn_into_skip();
18131813
did_something = true;
18141814
}
18151815
}

src/analyses/interval_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void instrument_intervals(
7979
{
8080
goto_programt::targett t=i_it;
8181
goto_function.body.insert_before_swap(i_it);
82-
t->make_assumption(conjunction(assertion));
82+
*t = goto_programt::make_assumption(conjunction(assertion));
8383
i_it++; // goes to original instruction
8484
t->source_location=i_it->source_location;
8585
}

src/assembler/remove_asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void remove_asmt::process_function(
495495
{
496496
goto_programt tmp_dest;
497497
process_instruction(*it, tmp_dest);
498-
it->make_skip();
498+
it->turn_into_skip();
499499
did_something = true;
500500

501501
goto_programt::targett next = it;

src/goto-analyzer/taint_analysis.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,20 @@ void taint_analysist::instrument(
166166
code_set_may.op0()=where;
167167
code_set_may.op1()=
168168
address_of_exprt(string_constantt(rule.taint));
169-
goto_programt::targett t=insert_after.add_instruction();
170-
t->make_other(code_set_may);
171-
t->source_location=instruction.source_location;
169+
insert_after.add(goto_programt::make_other(
170+
code_set_may, instruction.source_location));
172171
}
173172
break;
174173

175174
case taint_parse_treet::rulet::SINK:
176175
{
177-
goto_programt::targett t=insert_before.add_instruction();
178176
binary_predicate_exprt get_may(
179177
where,
180178
"get_may",
181179
address_of_exprt(string_constantt(rule.taint)));
182-
t->make_assertion(not_exprt(get_may));
183-
t->source_location=instruction.source_location;
180+
goto_programt::targett t =
181+
insert_before.add(goto_programt::make_assertion(
182+
not_exprt(get_may), instruction.source_location));
184183
t->source_location.set_property_class(
185184
"taint rule "+id2string(rule.id));
186185
t->source_location.set_comment(rule.message);
@@ -194,9 +193,8 @@ void taint_analysist::instrument(
194193
code_clear_may.op0()=where;
195194
code_clear_may.op1()=
196195
address_of_exprt(string_constantt(rule.taint));
197-
goto_programt::targett t=insert_after.add_instruction();
198-
t->make_other(code_clear_may);
199-
t->source_location=instruction.source_location;
196+
insert_after.add(goto_programt::make_other(
197+
code_clear_may, instruction.source_location));
200198
}
201199
break;
202200
}
@@ -285,14 +283,13 @@ bool taint_analysist::operator()(
285283
f_it->first!=goto_functionst::entry_point())
286284
{
287285
const symbolt &symbol = ns.lookup(f_it->first);
288-
goto_programt::targett t=calls.add_instruction();
289286
const code_function_callt call(symbol.symbol_expr());
290-
t->make_function_call(call);
291-
calls.add_instruction()->make_goto(
292-
end.instructions.begin(), true_exprt());
293-
goto_programt::targett g=gotos.add_instruction();
294-
g->make_goto(
295-
t, side_effect_expr_nondett(bool_typet(), symbol.location));
287+
goto_programt::targett t =
288+
calls.add(goto_programt::make_function_call(call));
289+
calls.add(
290+
goto_programt::make_goto(end.instructions.begin(), true_exprt()));
291+
gotos.add(goto_programt::make_goto(
292+
t, side_effect_expr_nondett(bool_typet(), symbol.location)));
296293
}
297294

298295
goto_functionst::goto_functiont &entry=

0 commit comments

Comments
 (0)