Skip to content

Commit 98f56a4

Browse files
committed
Removes subset relationship check from contracts
Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent 1e42716 commit 98f56a4

File tree

10 files changed

+12
-66
lines changed

10 files changed

+12
-66
lines changed

regression/contracts/assigns_enforce_22/main.c renamed to regression/contracts/assigns_enforce_21/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int x = 0;
55

6-
void quz() __CPROVER_assigns(x)
6+
void quz() __CPROVER_assigns(x) __CPROVER_ensures(x == -1)
77
{
88
x = -1;
99
}
@@ -17,6 +17,7 @@ void bar(int *y, int w) __CPROVER_assigns(*y)
1717
{
1818
*y = 3;
1919
w = baz();
20+
assert(w == 5);
2021
quz();
2122
}
2223

regression/contracts/assigns_enforce_22/test.desc renamed to regression/contracts/assigns_enforce_21/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
CORE
22
main.c
3-
--enforce-contract foo
3+
--enforce-contract foo --replace-call-with-contract quz
44
^EXIT=10$
55
^SIGNAL=0$
66
main.c function bar
77
^\[bar.\d+\] line \d+ Check that \*y is assignable: SUCCESS$
8+
^\[bar.\d+\] line \d+ Check that x is assignable: FAILURE$
89
^\[baz.\d+\] line \d+ Check that w is assignable: SUCCESS$
910
^\[foo.\d+\] line \d+ Check that w is assignable: SUCCESS$
1011
^\[foo.\d+\] line \d+ Check that z is assignable: SUCCESS$
11-
^\[quz.\d+\] line \d+ Check that x is assignable: FAILURE$
1212
^VERIFICATION FAILED$
1313
--
1414
--

regression/contracts/assigns_replace_08/test.desc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ main.c
33
--enforce-contract foo --replace-call-with-contract bar _ --pointer-primitive-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
\[foo.\d+\] line \d+ Check that bar\'s assigns clause is a subset of foo\'s assigns clause: FAILURE$
76
\[foo.\d+\] line \d+ Check that \*z is assignable: FAILURE$
8-
^.* 2 of \d+ failed \(\d+ iteration.*\)$
7+
^.* 1 of \d+ failed \(\d+ iteration.*\)$
98
^VERIFICATION FAILED$
109
--
11-
\[\d+\] file main.c line \d+ Check that bar\'s assigns clause is a subset of foo\'s assigns clause: SUCCESS$
1210
\[\d+\] file main.c line \d+ Check that \*z is assignable: SUCCESS$
1311
^VERIFICATION SUCCESSFUL$
1412
--

regression/contracts/assigns_replace_09/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33
--replace-call-with-contract bar --enforce-contract foo
44
^EXIT=0$
55
^SIGNAL=0$
6-
\[foo.\d+\] line \d+ Check that bar\'s assigns clause is a subset of foo\'s assigns clause: SUCCESS$
76
\[foo.\d+\] line \d+ Check that \*z is assignable: SUCCESS$
87
^VERIFICATION SUCCESSFUL$
98
--

regression/contracts/assigns_validity_pointer_02/test.desc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ main.c
1313
^VERIFICATION SUCCESSFUL$
1414
--
1515
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: FAILURE$
16-
^\[foo.\d+\] line \d+ Check that bar\'s assigns clause is a subset of foo\'s assigns clause: FAILURE$
1716
^\[foo.\d+\] line \d+ Check that \*x is assignable: FAILURE$
18-
^\[foo.\d+\] line \d+ Check that baz\'s assigns clause is a subset of foo\'s assigns clause: FAILURE$
1917
--
2018
Verification:
2119
This test checks support for a NULL pointer that is assigned to by

regression/contracts/assigns_validity_pointer_04/test.desc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ main.c
33
--enforce-contract foo --replace-call-with-contract bar --replace-call-with-contract baz _ --pointer-primitive-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[foo.\d+\] line \d+ Check that bar\'s assigns clause is a subset of foo\'s assigns clause: FAILURE$
7-
^\[foo.\d+\] line \d+ Check that baz\'s assigns clause is a subset of foo\'s assigns clause: FAILURE$
86
^\[foo.\d+\] line \d+ Check that z is assignable: FAILURE$
9-
^.* 3 of \d+ failed \(\d+ iteration.*\)$
7+
^.* 1 of \d+ failed \(\d+ iteration.*\)$
108
^VERIFICATION FAILED$
119
// bar
1210
ASSERT \*foo::x > 0

src/goto-instrument/contracts/assigns.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,3 @@ exprt assigns_clauset::generate_containment_check(const exprt &lhs) const
150150
}
151151
return disjunction(condition);
152152
}
153-
154-
exprt assigns_clauset::generate_subset_check(
155-
const assigns_clauset &subassigns) const
156-
{
157-
if(subassigns.write_set.empty())
158-
return true_exprt();
159-
160-
exprt result = true_exprt();
161-
for(const auto &subtarget : subassigns.write_set)
162-
{
163-
exprt::operandst current_subtarget_found_conditions;
164-
for(const auto &target : write_set)
165-
{
166-
current_subtarget_found_conditions.push_back(
167-
target.generate_containment_check(subtarget.address));
168-
}
169-
result = and_exprt(result, disjunction(current_subtarget_found_conditions));
170-
}
171-
172-
return result;
173-
}

src/goto-instrument/contracts/assigns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class assigns_clauset
6363

6464
goto_programt generate_havoc_code(const source_locationt &) const;
6565
exprt generate_containment_check(const exprt &) const;
66-
exprt generate_subset_check(const assigns_clauset &) const;
6766

6867
const messaget &log;
6968
const namespacet &ns;

src/goto-instrument/contracts/contracts.cpp

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ code_contractst::create_ensures_instruction(
433433
bool code_contractst::apply_function_contract(
434434
const irep_idt &function,
435435
goto_programt &function_body,
436-
goto_programt::targett &target,
437-
const std::set<std::string> &enforced_functions)
436+
goto_programt::targett &target)
438437
{
439438
const auto &const_target =
440439
static_cast<const goto_programt::targett &>(target);
@@ -568,30 +567,9 @@ bool code_contractst::apply_function_contract(
568567
{
569568
assigns_clauset assigns_clause(targets.operands(), log, ns);
570569

571-
// Retrieve assigns clause of the caller function if exists.
572-
auto caller_assigns =
573-
to_code_with_contract_type(ns.lookup(function).type).assigns();
574-
575-
if(enforced_functions.find(function.c_str()) != enforced_functions.end())
576-
{
577-
// check subset relationship of assigns clause for called function
578-
assigns_clauset caller_assigns_clause(caller_assigns, log, ns);
579-
goto_programt subset_check_assertion;
580-
subset_check_assertion.add(goto_programt::make_assertion(
581-
caller_assigns_clause.generate_subset_check(assigns_clause),
582-
const_target->source_location));
583-
subset_check_assertion.instructions.back().source_location.set_comment(
584-
"Check that " + id2string(target_function) +
585-
"'s assigns clause is a subset of " +
586-
id2string(const_target->source_location.get_function()) +
587-
"'s assigns clause");
588-
insert_before_swap_and_advance(
589-
function_body, target, subset_check_assertion);
590-
}
591-
592570
// Havoc all targets in global write set
593571
auto assigns_havoc =
594-
assigns_clause.generate_havoc_code(const_target->source_location);
572+
assigns_clause.generate_havoc_code(target->source_location);
595573

596574
// Insert the non-deterministic assignment immediately before the call site.
597575
insert_before_swap_and_advance(function_body, target, assigns_havoc);
@@ -1097,9 +1075,7 @@ void code_contractst::add_contract_check(
10971075
dest.destructive_insert(dest.instructions.begin(), check);
10981076
}
10991077

1100-
bool code_contractst::replace_calls(
1101-
const std::set<std::string> &to_replace,
1102-
const std::set<std::string> &to_enforce)
1078+
bool code_contractst::replace_calls(const std::set<std::string> &to_replace)
11031079
{
11041080
if(to_replace.empty())
11051081
return false;
@@ -1123,7 +1099,7 @@ bool code_contractst::replace_calls(
11231099
continue;
11241100

11251101
fail |= apply_function_contract(
1126-
goto_function.first, goto_function.second.body, ins, to_enforce);
1102+
goto_function.first, goto_function.second.body, ins);
11271103
}
11281104
}
11291105
}

src/goto-instrument/contracts/contracts.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ class code_contractst
7474
/// it using `cbmc --function F`.
7575
///
7676
/// \return `true` on failure, `false` otherwise
77-
bool
78-
replace_calls(const std::set<std::string> &, const std::set<std::string> &);
77+
bool replace_calls(const std::set<std::string> &);
7978

8079
/// \brief Turn requires & ensures into assumptions and assertions for each of
8180
/// the named functions
@@ -178,8 +177,7 @@ class code_contractst
178177
bool apply_function_contract(
179178
const irep_idt &,
180179
goto_programt &,
181-
goto_programt::targett &,
182-
const std::set<std::string> &);
180+
goto_programt::targett &);
183181

184182
/// Instruments `wrapper_function` adding assumptions based on requires
185183
/// clauses and assertions based on ensures clauses.

0 commit comments

Comments
 (0)