Skip to content

Commit 94ae975

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 3ab3c5b commit 94ae975

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/goto-instrument/contracts/contracts.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,19 +1453,12 @@ void code_contractst::add_contract_check(
14531453
auto requires_contract = code_type.requires_contract();
14541454
auto ensures_contract = code_type.ensures_contract();
14551455
// build:
1456-
// if(nondet)
1457-
// decl ret
1458-
// decl parameter1 ...
1459-
// decl history_parameter1 ... [optional]
1460-
// assume(requires) [optional]
1461-
// ret=function(parameter1, ...)
1462-
// assert(ensures)
1463-
// skip: ...
1464-
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()));
1456+
// decl ret
1457+
// decl parameter1 ...
1458+
// decl history_parameter1 ... [optional]
1459+
// assume(requires) [optional]
1460+
// ret=function(parameter1, ...)
1461+
// assert(ensures)
14691462

14701463
goto_programt check;
14711464

@@ -1478,17 +1471,19 @@ void code_contractst::add_contract_check(
14781471
// This object tracks replacements that are common to ENSURES and REQUIRES.
14791472
replace_symbolt common_replace;
14801473

1474+
const auto &source_location = function_symbol.location;
1475+
14811476
// decl ret
14821477
optionalt<code_returnt> return_stmt;
14831478
if(code_type.return_type() != empty_typet())
14841479
{
14851480
symbol_exprt r = new_tmp_symbol(
14861481
code_type.return_type(),
1487-
skip->source_location(),
1482+
source_location,
14881483
function_symbol.mode,
14891484
symbol_table)
14901485
.symbol_expr();
1491-
check.add(goto_programt::make_decl(r, skip->source_location()));
1486+
check.add(goto_programt::make_decl(r, source_location));
14921487

14931488
call.lhs() = r;
14941489
return_stmt = code_returnt(r);
@@ -1509,13 +1504,13 @@ void code_contractst::add_contract_check(
15091504
const symbolt &parameter_symbol = ns.lookup(parameter);
15101505
symbol_exprt p = new_tmp_symbol(
15111506
parameter_symbol.type,
1512-
skip->source_location(),
1507+
source_location,
15131508
parameter_symbol.mode,
15141509
symbol_table)
15151510
.symbol_expr();
1516-
check.add(goto_programt::make_decl(p, skip->source_location()));
1511+
check.add(goto_programt::make_decl(p, source_location));
15171512
check.add(goto_programt::make_assignment(
1518-
p, parameter_symbol.symbol_expr(), skip->source_location()));
1513+
p, parameter_symbol.symbol_expr(), source_location));
15191514

15201515
call.arguments().push_back(p);
15211516

@@ -1577,7 +1572,7 @@ void code_contractst::add_contract_check(
15771572
}
15781573

15791574
// ret=mangled_function(parameter1, ...)
1580-
check.add(goto_programt::make_function_call(call, skip->source_location()));
1575+
check.add(goto_programt::make_function_call(call, source_location));
15811576

15821577
// Generate: assert(ensures)
15831578
if(ensures.is_not_nil())
@@ -1598,15 +1593,12 @@ void code_contractst::add_contract_check(
15981593
if(code_type.return_type() != empty_typet())
15991594
{
16001595
check.add(goto_programt::make_set_return_value(
1601-
return_stmt.value().return_value(), skip->source_location()));
1596+
return_stmt.value().return_value(), source_location));
16021597
}
16031598

16041599
// kill the is_fresh memory map
16051600
visitor.add_memory_map_dead(check);
16061601

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

0 commit comments

Comments
 (0)