-
Notifications
You must be signed in to change notification settings - Fork 277
Function contracts: check loop freeness before instrumentation, skip assignments to locals and prune write set using CFG info. #6533
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
remi-delmas-3000
merged 1 commit into
diffblue:develop
from
remi-delmas-3000:function-contracts-prune-write-set
Dec 18, 2021
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
void assigns_single(int a[], int len) __CPROVER_assigns(a) | ||
void assigns_single(int a[], int len) | ||
{ | ||
int i; | ||
__CPROVER_assume(0 <= i && i < len); | ||
a[i] = 0; | ||
} | ||
|
||
void assigns_range(int a[], int len) __CPROVER_assigns(a) | ||
{ | ||
} | ||
|
||
void assigns_big_range(int a[], int len) __CPROVER_assigns(a) | ||
void uses_assigns(int a[], int len) | ||
__CPROVER_assigns(__CPROVER_POINTER_OBJECT(a)) | ||
{ | ||
assigns_single(a, len); | ||
assigns_range(a, len); | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
assigns_big_range(arr, 10); | ||
uses_assigns(arr, 10); | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
void assigns_ptr(int *x) __CPROVER_assigns(*x) | ||
void assigns_ptr(int *x) | ||
{ | ||
*x = 200; | ||
} | ||
|
||
void assigns_range(int a[], int len) __CPROVER_assigns(a) | ||
void uses_assigns(int a[], int i, int len) | ||
// clang-format off | ||
__CPROVER_requires(0 <= i && i < len) | ||
__CPROVER_assigns(*(&a[i])) | ||
// clang-format on | ||
{ | ||
int *ptr = &(a[7]); | ||
int *ptr = &(a[i]); | ||
assigns_ptr(ptr); | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
assigns_range(arr, 10); | ||
|
||
int i; | ||
__CPROVER_assume(0 <= i && i < 10); | ||
uses_assigns(arr, i, 10); | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
CORE | ||
main.c | ||
--enforce-contract assigns_range | ||
^EXIT=10$ | ||
--enforce-contract uses_assigns | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
^\[assigns_ptr\.\d+\] line \d+ Check that \*x is assignable: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Checks whether verification fails when an assigns clause of a function | ||
indicates the pointer might change, but one of its internal function only | ||
modified its content. | ||
Checks whether verification succeeds for array elements at a symbolic index. |
9 changes: 4 additions & 5 deletions
9
regression/contracts/assigns_enforce_detect_local_statics/test.desc
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
#include <stdlib.h> | ||
|
||
int f1(int *a, int *b) __CPROVER_assigns(*a, b) | ||
int f(int *a) __CPROVER_assigns() | ||
{ | ||
b = (int *)malloc(sizeof(int)); | ||
*b = 5; | ||
a = (int *)malloc(sizeof(int)); | ||
*a = 5; | ||
} | ||
|
||
int main() | ||
{ | ||
int m = 4; | ||
int n = 3; | ||
f1(&m, &n); | ||
f(&m); | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
CORE | ||
main.c | ||
--enforce-contract f1 | ||
--enforce-contract f | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[f\.\d+\] line \d+ Check that \*a is assignable: SUCCESS | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test checks that verification succeeds when a formal parameter pointer outside of the assigns clause is instead pointed as freshly allocated memory before being assigned. | ||
This test checks that verification succeeds when a formal parameter | ||
with a pointer type is first updated to point to a locally malloc'd object | ||
before being assigned to. |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
CORE | ||
main.c | ||
--enforce-contract f1 | ||
^EXIT=6$ | ||
^Invariant check failed$ | ||
^Condition: is_loop_free | ||
^Reason: Loops remain in function 'f1', assigns clause checking instrumentation cannot be applied\. | ||
^EXIT=(127|134)$ | ||
^SIGNAL=0$ | ||
Unable to complete instrumentation, as this malloc may be in a loop.$ | ||
-- | ||
-- | ||
This test checks that an error is thrown when malloc is called within a loop. |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
CORE | ||
main.c | ||
--enforce-contract f1 | ||
--enforce-contract f | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[f\.\d+\] line \d+ Check that \*a is assignable: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Checks whether verification succeeds when a formal parameter pointer outside | ||
of the assigns clause is instead pointed at the location of a member of a | ||
freshly allocated struct before being assigned. | ||
Checks whether verification succeeds when a pointer deref that is not | ||
specified in the assigns clause is first pointed at a member of a | ||
locally malloc'd struct before being assigned. |
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
CORE | ||
main.c | ||
--enforce-contract f1 | ||
--enforce-contract f | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[f\.\d+\] line \d+ Check that \*a is assignable: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Checks whether verification succeeds when a formal parameter pointer outside | ||
of the assigns clause is assigned after being pointed at the location of a | ||
member of a sub-struct of a freshly allocated struct before being assigned. | ||
This is meant to show that all contained members (and their contained members) | ||
of assignable structs are valid to assign. | ||
Checks whether verification succeeds when a pointer deref that is not | ||
specified in the assigns clause is first pointed at a member of a locally | ||
malloc'd struct before being assigned (with extra nesting). |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CORE | ||
main.c | ||
--enforce-contract f1 | ||
--enforce-contract f | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.