Skip to content

CONTRACTS: Convenience updates for function_pointer_obeys_contract_exprt #7082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/ansi-c/c_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,22 @@ class function_pointer_obeys_contract_exprt : public exprt
return op0();
}

const exprt &contract() const
const symbol_exprt &contract_symbol_expr() const
{
return to_symbol_expr(op1().operands().at(0));
}

symbol_exprt &contract_symbol_expr()
{
return to_symbol_expr(op1().operands().at(0));
}

const exprt &address_of_contract() const
{
return op1();
}

exprt &contract()
exprt &address_of_contract()
{
return op1();
}
Expand Down
14 changes: 7 additions & 7 deletions src/ansi-c/c_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,14 @@ void c_typecheck_baset::typecheck_spec_function_pointer_obeys_contract(
}

// second parameter must be the address of a function symbol
auto &contract = obeys_expr.contract();
typecheck_expr(contract);
auto &address_of_contract = obeys_expr.address_of_contract();
typecheck_expr(address_of_contract);

if(
contract.id() != ID_address_of ||
to_address_of_expr(contract).object().id() != ID_symbol ||
contract.type().id() != ID_pointer ||
to_pointer_type(contract.type()).subtype().id() != ID_code)
address_of_contract.id() != ID_address_of ||
to_address_of_expr(address_of_contract).object().id() != ID_symbol ||
address_of_contract.type().id() != ID_pointer ||
to_pointer_type(address_of_contract.type()).subtype().id() != ID_code)
{
error().source_location = expr.source_location();
error() << "the second parameter of the requires_contract/ensures_contract "
Expand All @@ -1056,7 +1056,7 @@ void c_typecheck_baset::typecheck_spec_function_pointer_obeys_contract(
throw 0;
}

if(function_pointer.type() != contract.type())
if(function_pointer.type() != address_of_contract.type())
{
error().source_location = expr.source_location();
error() << "the first and second parameter of the "
Expand Down
8 changes: 4 additions & 4 deletions src/goto-instrument/contracts/contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,10 +1428,10 @@ void code_contractst::assert_function_pointer_obeys_contract(
comment << "Assert function pointer '"
<< from_expr_using_mode(ns, mode, expr.function_pointer())
<< "' obeys contract '"
<< from_expr_using_mode(ns, mode, expr.contract()) << "'";
<< from_expr_using_mode(ns, mode, expr.address_of_contract()) << "'";
loc.set_comment(comment.str());
code_assertt assert_expr(
equal_exprt{expr.function_pointer(), expr.contract()});
equal_exprt{expr.function_pointer(), expr.address_of_contract()});
assert_expr.add_source_location() = loc;
goto_programt instructions;
converter.goto_convert(assert_expr, instructions, mode);
Expand All @@ -1448,10 +1448,10 @@ void code_contractst::assume_function_pointer_obeys_contract(
comment << "Assume function pointer '"
<< from_expr_using_mode(ns, mode, expr.function_pointer())
<< "' obeys contract '"
<< from_expr_using_mode(ns, mode, expr.contract()) << "'";
<< from_expr_using_mode(ns, mode, expr.address_of_contract()) << "'";
loc.set_comment(comment.str());
dest.add(goto_programt::make_assignment(
expr.function_pointer(), expr.contract(), loc));
expr.function_pointer(), expr.address_of_contract(), loc));
}

void code_contractst::add_contract_check(
Expand Down