-
Notifications
You must be signed in to change notification settings - Fork 274
Skip function parameters and auxiliary variables when checking assigns clauses and check loop-freeness #6527
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
Closed
remi-delmas-3000
wants to merge
2
commits into
diffblue:develop
from
remi-delmas-3000:exclude-auxiliaries-from-assigns-clause-checking
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
int foo(int *arr) | ||
// clang-format off | ||
__CPROVER_assigns(__CPROVER_POINTER_OBJECT(arr)) | ||
// clang-format off | ||
{ | ||
for(int i = 0; i < 10; i++) | ||
arr[i] = i; | ||
|
||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
foo(arr); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
main.c | ||
--enforce-contract foo | ||
^--- begin invariant violation report ---$ | ||
^Invariant check failed$ | ||
^Condition: is_loop_free\(.*\) | ||
^Reason: Loops remain in function 'foo', assigns clause checking instrumentation cannot be applied\.$ | ||
^EXIT=(127|134)$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
This test checks that loops that remain in the program when attempting to | ||
instrument assigns clauses are detected and trigger an INVARIANT. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1128,7 +1128,9 @@ bool code_contractst::check_frame_conditions_function(const irep_idt &function) | |
return true; | ||
} | ||
|
||
if(check_for_looped_mallocs(function_obj->second.body)) | ||
auto &function_body = function_obj->second.body; | ||
|
||
if(check_for_looped_mallocs(function_body)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is no longer necessary, you can remove it. It checks whether there is malloc within loops, but we assume contract instrumentation happens after all loops have been unrolled. |
||
{ | ||
return true; | ||
} | ||
|
@@ -1142,21 +1144,24 @@ bool code_contractst::check_frame_conditions_function(const irep_idt &function) | |
function, | ||
symbol_table); | ||
|
||
// detect and add static local variables | ||
// Detect and add static local variables | ||
assigns.add_static_locals_to_write_set(goto_functions, function); | ||
|
||
// Add formal parameters to write set | ||
for(const auto ¶m : to_code_type(target.type).parameters()) | ||
assigns.add_to_write_set(ns.lookup(param.get_identifier()).symbol_expr()); | ||
|
||
auto instruction_it = function_obj->second.body.instructions.begin(); | ||
auto instruction_it = function_body.instructions.begin(); | ||
for(const auto &car : assigns.get_write_set()) | ||
{ | ||
auto snapshot_instructions = car.generate_snapshot_instructions(); | ||
insert_before_swap_and_advance( | ||
function_obj->second.body, instruction_it, snapshot_instructions); | ||
function_body, instruction_it, snapshot_instructions); | ||
}; | ||
|
||
// Restore internal coherence in the programs | ||
goto_functions.update(); | ||
|
||
// Full inlining of the function body | ||
// Inlining is performed so that function calls to a same function | ||
// occurring under different write sets get instrumented specifically | ||
|
@@ -1168,15 +1173,23 @@ bool code_contractst::check_frame_conditions_function(const irep_idt &function) | |
decorated.get_recursive_function_warnings_count() == 0, | ||
"Recursive functions found during inlining"); | ||
|
||
// restore internal invariants | ||
// Clean up possible fake loops that are due to `IF 0!=0 GOTO i` instructions | ||
simplify_gotos(function_body, ns); | ||
|
||
// Restore internal coherence in the programs | ||
goto_functions.update(); | ||
|
||
INVARIANT( | ||
is_loop_free(function_body, ns, log), | ||
"Loops remain in function '" + id2string(function) + | ||
"', assigns clause checking instrumentation cannot be applied."); | ||
|
||
// Insert write set inclusion checks. | ||
check_frame_conditions( | ||
function_obj->first, | ||
function_obj->second.body, | ||
function, | ||
function_body, | ||
instruction_it, | ||
function_obj->second.body.instructions.end(), | ||
function_body.instructions.end(), | ||
assigns, | ||
// skip checks on function parameter assignments | ||
true); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this loop?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds a loop freeness check before running the instrumentation, so the loop needs to be eliminated to satisfy this loop-freeness check.
This manual unrolling of loops is just a quick and dirty fix. A better solution would be to modify
chain.sh
add a pass of loop unrolling or loop contracts instrumentation.