Skip to content

Commit 281f750

Browse files
committed
Code contracts: remove useless skip statement
All that was used was its source location, which we can obtain in a different way.
1 parent 3be5294 commit 281f750

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/goto-instrument/contracts/contracts.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,6 @@ void code_contractst::add_contract_check(
14621462
// assert(ensures)
14631463
// skip: ...
14641464

1465-
// build skip so that if(nondet) can refer to it
1466-
goto_programt tmp_skip;
1467-
goto_programt::targett skip =
1468-
tmp_skip.add(goto_programt::make_skip(ensures.source_location()));
1469-
14701465
goto_programt check;
14711466

14721467
// prepare function call including all declarations
@@ -1478,17 +1473,19 @@ void code_contractst::add_contract_check(
14781473
// This object tracks replacements that are common to ENSURES and REQUIRES.
14791474
replace_symbolt common_replace;
14801475

1476+
const auto &source_location = function_symbol.location;
1477+
14811478
// decl ret
14821479
optionalt<code_returnt> return_stmt;
14831480
if(code_type.return_type() != empty_typet())
14841481
{
14851482
symbol_exprt r = new_tmp_symbol(
14861483
code_type.return_type(),
1487-
skip->source_location(),
1484+
source_location,
14881485
function_symbol.mode,
14891486
symbol_table)
14901487
.symbol_expr();
1491-
check.add(goto_programt::make_decl(r, skip->source_location()));
1488+
check.add(goto_programt::make_decl(r, source_location));
14921489

14931490
call.lhs() = r;
14941491
return_stmt = code_returnt(r);
@@ -1509,13 +1506,13 @@ void code_contractst::add_contract_check(
15091506
const symbolt &parameter_symbol = ns.lookup(parameter);
15101507
symbol_exprt p = new_tmp_symbol(
15111508
parameter_symbol.type,
1512-
skip->source_location(),
1509+
source_location,
15131510
parameter_symbol.mode,
15141511
symbol_table)
15151512
.symbol_expr();
1516-
check.add(goto_programt::make_decl(p, skip->source_location()));
1513+
check.add(goto_programt::make_decl(p, source_location));
15171514
check.add(goto_programt::make_assignment(
1518-
p, parameter_symbol.symbol_expr(), skip->source_location()));
1515+
p, parameter_symbol.symbol_expr(), source_location));
15191516

15201517
call.arguments().push_back(p);
15211518

@@ -1577,7 +1574,7 @@ void code_contractst::add_contract_check(
15771574
}
15781575

15791576
// ret=mangled_function(parameter1, ...)
1580-
check.add(goto_programt::make_function_call(call, skip->source_location()));
1577+
check.add(goto_programt::make_function_call(call, source_location));
15811578

15821579
// Generate: assert(ensures)
15831580
if(ensures.is_not_nil())
@@ -1598,15 +1595,12 @@ void code_contractst::add_contract_check(
15981595
if(code_type.return_type() != empty_typet())
15991596
{
16001597
check.add(goto_programt::make_set_return_value(
1601-
return_stmt.value().return_value(), skip->source_location()));
1598+
return_stmt.value().return_value(), source_location));
16021599
}
16031600

16041601
// kill the is_fresh memory map
16051602
visitor.add_memory_map_dead(check);
16061603

1607-
// add final instruction
1608-
check.destructive_append(tmp_skip);
1609-
16101604
// prepend the new code to dest
16111605
dest.destructive_insert(dest.instructions.begin(), check);
16121606

0 commit comments

Comments
 (0)