Skip to content

Commit 175a609

Browse files
Merge pull request #7082 from remi-delmas-3000/function-pointer-obeys-contract-exprt-improvements
CONTRACTS: Convenience updates for `function_pointer_obeys_contract_exprt`
2 parents e448fd4 + 7386758 commit 175a609

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/ansi-c/c_expr.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,22 @@ class function_pointer_obeys_contract_exprt : public exprt
364364
return op0();
365365
}
366366

367-
const exprt &contract() const
367+
const symbol_exprt &contract_symbol_expr() const
368+
{
369+
return to_symbol_expr(op1().operands().at(0));
370+
}
371+
372+
symbol_exprt &contract_symbol_expr()
373+
{
374+
return to_symbol_expr(op1().operands().at(0));
375+
}
376+
377+
const exprt &address_of_contract() const
368378
{
369379
return op1();
370380
}
371381

372-
exprt &contract()
382+
exprt &address_of_contract()
373383
{
374384
return op1();
375385
}

src/ansi-c/c_typecheck_code.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,14 +1040,14 @@ void c_typecheck_baset::typecheck_spec_function_pointer_obeys_contract(
10401040
}
10411041

10421042
// second parameter must be the address of a function symbol
1043-
auto &contract = obeys_expr.contract();
1044-
typecheck_expr(contract);
1043+
auto &address_of_contract = obeys_expr.address_of_contract();
1044+
typecheck_expr(address_of_contract);
10451045

10461046
if(
1047-
contract.id() != ID_address_of ||
1048-
to_address_of_expr(contract).object().id() != ID_symbol ||
1049-
contract.type().id() != ID_pointer ||
1050-
to_pointer_type(contract.type()).subtype().id() != ID_code)
1047+
address_of_contract.id() != ID_address_of ||
1048+
to_address_of_expr(address_of_contract).object().id() != ID_symbol ||
1049+
address_of_contract.type().id() != ID_pointer ||
1050+
to_pointer_type(address_of_contract.type()).subtype().id() != ID_code)
10511051
{
10521052
error().source_location = expr.source_location();
10531053
error() << "the second parameter of the requires_contract/ensures_contract "
@@ -1056,7 +1056,7 @@ void c_typecheck_baset::typecheck_spec_function_pointer_obeys_contract(
10561056
throw 0;
10571057
}
10581058

1059-
if(function_pointer.type() != contract.type())
1059+
if(function_pointer.type() != address_of_contract.type())
10601060
{
10611061
error().source_location = expr.source_location();
10621062
error() << "the first and second parameter of the "

src/goto-instrument/contracts/contracts.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,10 @@ void code_contractst::assert_function_pointer_obeys_contract(
14281428
comment << "Assert function pointer '"
14291429
<< from_expr_using_mode(ns, mode, expr.function_pointer())
14301430
<< "' obeys contract '"
1431-
<< from_expr_using_mode(ns, mode, expr.contract()) << "'";
1431+
<< from_expr_using_mode(ns, mode, expr.address_of_contract()) << "'";
14321432
loc.set_comment(comment.str());
14331433
code_assertt assert_expr(
1434-
equal_exprt{expr.function_pointer(), expr.contract()});
1434+
equal_exprt{expr.function_pointer(), expr.address_of_contract()});
14351435
assert_expr.add_source_location() = loc;
14361436
goto_programt instructions;
14371437
converter.goto_convert(assert_expr, instructions, mode);
@@ -1448,10 +1448,10 @@ void code_contractst::assume_function_pointer_obeys_contract(
14481448
comment << "Assume function pointer '"
14491449
<< from_expr_using_mode(ns, mode, expr.function_pointer())
14501450
<< "' obeys contract '"
1451-
<< from_expr_using_mode(ns, mode, expr.contract()) << "'";
1451+
<< from_expr_using_mode(ns, mode, expr.address_of_contract()) << "'";
14521452
loc.set_comment(comment.str());
14531453
dest.add(goto_programt::make_assignment(
1454-
expr.function_pointer(), expr.contract(), loc));
1454+
expr.function_pointer(), expr.address_of_contract(), loc));
14551455
}
14561456

14571457
void code_contractst::add_contract_check(

0 commit comments

Comments
 (0)