Skip to content

Invoke goto_functions.update() after inlining #6493

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
merged 1 commit into from
Dec 1, 2021
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
6 changes: 6 additions & 0 deletions regression/contracts/invar_check_large/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main()
int r = 1;
while(h > l)
// clang-format off
__CPROVER_assigns(arr0, arr1, arr2, arr3, arr4, h, l, r)
__CPROVER_loop_invariant(
// Turn off `clang-format` because it breaks the `==>` operator.
h >= l &&
Expand Down Expand Up @@ -61,6 +62,11 @@ int main()
r = h;
l++;
}
else
{
h--;
l++;
}
}
else if(*(arr[h]) <= pivot)
{
Expand Down
2 changes: 1 addition & 1 deletion regression/contracts/invar_check_large/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ main.c
^EXIT=0$
^SIGNAL=0$
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
^\[main.\d+\] .* Check that loop invariant is preserved: SUCCESS$
^\[main.assertion.1\] .* assertion 0 <= r && r < 5: SUCCESS$
^\[main.assertion.2\] .* assertion \*\(arr\[r\]\) == pivot: SUCCESS$
^\[main.assertion.3\] .* assertion 0 < r ==> arr0 <= pivot: SUCCESS$
Expand Down
18 changes: 14 additions & 4 deletions src/goto-instrument/contracts/contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,14 @@ void code_contractst::apply_loop_contract(
const irep_idt &function_name,
goto_functionst::goto_functiont &goto_function)
{
local_may_aliast local_may_alias(goto_function);
natural_loops_mutablet natural_loops(goto_function.body);

if(!natural_loops.loop_map.size())
const bool may_have_loops = std::any_of(
goto_function.body.instructions.begin(),
goto_function.body.instructions.end(),
[](const goto_programt::instructiont &instruction) {
return instruction.is_backwards_goto();
});

if(!may_have_loops)
return;

inlining_decoratort decorated(log.get_message_handler());
Expand All @@ -787,6 +791,12 @@ void code_contractst::apply_loop_contract(
decorated.get_recursive_function_warnings_count() == 0,
"Recursive functions found during inlining");

// restore internal invariants
goto_functions.update();

local_may_aliast local_may_alias(goto_function);
natural_loops_mutablet natural_loops(goto_function.body);

// A graph node type that stores information about a loop.
// We create a DAG representing nesting of various loops in goto_function,
// sort them topologically, and instrument them in the top-sorted order.
Expand Down