Skip to content

Commit 5f0962e

Browse files
author
Daniel Kroening
committed
use goto_programt::instructiont constructor
This ensures full initialization of the class.
1 parent eb7cfb1 commit 5f0962e

File tree

5 files changed

+50
-40
lines changed

5 files changed

+50
-40
lines changed

src/analyses/goto_check.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,13 +1438,16 @@ void goto_checkt::add_guarded_claim(
14381438
goto_program_instruction_typet type=
14391439
enable_assert_to_assume?ASSUME:ASSERT;
14401440

1441-
goto_programt::targett t=new_code.add_instruction(type);
1441+
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1442+
static_cast<const codet &>(get_nil_irep()),
1443+
source_location,
1444+
type,
1445+
std::move(new_expr),
1446+
{}));
14421447

14431448
std::string source_expr_string;
14441449
get_language_from_mode(mode)->from_expr(src_expr, source_expr_string, ns);
14451450

1446-
t->set_condition(std::move(new_expr));
1447-
t->source_location=source_location;
14481451
t->source_location.set_comment(comment+" in "+source_expr_string);
14491452
t->source_location.set_property_class(property_class);
14501453
}
@@ -1739,10 +1742,13 @@ void goto_checkt::goto_check(
17391742
goto_program_instruction_typet type=
17401743
enable_assert_to_assume?ASSUME:ASSERT;
17411744

1742-
goto_programt::targett t=new_code.add_instruction(type);
1745+
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1746+
static_cast<const codet &>(get_nil_irep()),
1747+
i.source_location,
1748+
type,
1749+
false_exprt(),
1750+
{}));
17431751

1744-
t->set_condition(false_exprt());
1745-
t->source_location=i.source_location;
17461752
t->source_location.set_property_class("error label");
17471753
t->source_location.set_comment("error label "+label);
17481754
t->source_location.set("user-provided", true);

src/goto-instrument/unwind.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ void goto_unwindt::copy_segment(
4848

4949
for(goto_programt::const_targett t=start; t!=end; t++)
5050
{
51-
goto_programt::targett t_new=goto_program.add_instruction();
52-
*t_new=*t;
51+
// copy the instruction
52+
goto_programt::targett t_new =
53+
goto_program.add(goto_programt::instructiont(*t));
5354
unwind_log.insert(t_new, t->location_number);
5455
target_vector.push_back(t_new); // store copied instruction
5556
}

src/goto-programs/goto_convert_functions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ void goto_convert_functionst::convert_function(
182182
end_location.make_nil();
183183

184184
goto_programt tmp_end_function;
185-
goto_programt::targett end_function=tmp_end_function.add_instruction();
186-
end_function->type=END_FUNCTION;
187-
end_function->source_location=end_location;
185+
goto_programt::targett end_function =
186+
tmp_end_function.add(goto_programt::make_end_function(end_location));
188187

189188
targets=targetst();
190189
targets.set_return(end_function);

src/goto-programs/goto_convert_side_effect.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,12 @@ void goto_convertt::remove_side_effect(
594594
}
595595
else if(statement==ID_throw)
596596
{
597-
goto_programt::targett t=dest.add_instruction(THROW);
598-
t->code = code_expressiont(
599-
side_effect_expr_throwt(
600-
expr.find(ID_exception_list), expr.type(), expr.source_location()));
601-
t->code.op0().operands().swap(expr.operands());
602-
t->code.add_source_location()=expr.source_location();
603-
t->source_location=expr.source_location();
597+
codet code = code_expressiont(side_effect_expr_throwt(
598+
expr.find(ID_exception_list), expr.type(), expr.source_location()));
599+
code.op0().operands().swap(expr.operands());
600+
code.add_source_location() = expr.source_location();
601+
dest.add(goto_programt::instructiont(
602+
std::move(code), expr.source_location(), THROW, nil_exprt(), {}));
604603

605604
// the result can't be used, these are void
606605
expr.make_nil();

src/goto-programs/string_instrumentation.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -833,24 +833,7 @@ void string_instrumentationt::invalidate_buffer(
833833
from_integer(0, cntr_sym.type),
834834
target->source_location));
835835

836-
goto_programt::targett check=dest.add_instruction();
837-
838-
goto_programt::targett invalidate=dest.add_instruction(ASSIGN);
839-
invalidate->source_location=target->source_location;
840-
841-
const plus_exprt plus(
842-
cntr_sym.symbol_expr(), from_integer(1, unsigned_int_type()));
843-
844-
dest.add(goto_programt::make_assignment(
845-
cntr_sym.symbol_expr(), plus, target->source_location));
846-
847-
dest.add(
848-
goto_programt::make_goto(check, true_exprt(), target->source_location));
849-
850-
goto_programt::targett exit =
851-
dest.add(goto_programt::make_skip(target->source_location));
852-
853-
exprt cnt_bs, bufp;
836+
exprt bufp;
854837

855838
if(buf_type.id()==ID_pointer)
856839
bufp=buffer;
@@ -861,9 +844,6 @@ void string_instrumentationt::invalidate_buffer(
861844
bufp=address_of_exprt(index);
862845
}
863846

864-
const plus_exprt b_plus_i(bufp, cntr_sym.symbol_expr());
865-
const dereference_exprt deref(b_plus_i, buf_type.subtype());
866-
867847
exprt condition;
868848

869849
if(limit==0)
@@ -873,7 +853,32 @@ void string_instrumentationt::invalidate_buffer(
873853
condition = binary_relation_exprt(
874854
cntr_sym.symbol_expr(), ID_gt, from_integer(limit, unsigned_int_type()));
875855

876-
*check = goto_programt::make_goto(exit, condition, target->source_location);
856+
goto_programt::targett check = dest.add(
857+
goto_programt::make_incomplete_goto(condition, target->source_location));
858+
859+
goto_programt::targett invalidate = dest.add(goto_programt::instructiont(
860+
static_cast<const codet &>(get_nil_irep()),
861+
target->source_location,
862+
ASSIGN,
863+
nil_exprt(),
864+
{}));
865+
866+
const plus_exprt plus(
867+
cntr_sym.symbol_expr(), from_integer(1, unsigned_int_type()));
868+
869+
dest.add(goto_programt::make_assignment(
870+
cntr_sym.symbol_expr(), plus, target->source_location));
871+
872+
dest.add(
873+
goto_programt::make_goto(check, true_exprt(), target->source_location));
874+
875+
goto_programt::targett exit =
876+
dest.add(goto_programt::make_skip(target->source_location));
877+
878+
check->complete_goto(exit);
879+
880+
const plus_exprt b_plus_i(bufp, cntr_sym.symbol_expr());
881+
const dereference_exprt deref(b_plus_i, buf_type.subtype());
877882

878883
const side_effect_expr_nondett nondet(
879884
buf_type.subtype(), target->source_location);

0 commit comments

Comments
 (0)