-
Notifications
You must be signed in to change notification settings - Fork 274
Check for validity of pointers in assigns clause #6077
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
int *z; | ||
|
||
void bar(int *x, int *y) __CPROVER_assigns(*x, *y) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3 && (y == NULL || *y == 5)) | ||
{ | ||
*x = 3; | ||
if(y != NULL) | ||
*y = 5; | ||
} | ||
|
||
void baz() __CPROVER_assigns(*z) __CPROVER_ensures(z == NULL || *z == 7) | ||
{ | ||
if(z != NULL) | ||
*z = 7; | ||
} | ||
|
||
void foo(int *x) __CPROVER_assigns(*x) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3) | ||
{ | ||
bar(x, NULL); | ||
z == NULL; | ||
baz(); | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
foo(&n); | ||
|
||
assert(n == 3); | ||
assert(z == NULL || *z == 7); | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
regression/contracts/assigns_validity_pointer_01/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CORE | ||
main.c | ||
--enforce-contract foo --replace-call-with-contract bar --replace-call-with-contract baz | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
SUCCESS | ||
// bar | ||
ASSERT \*x > 0 | ||
IF !\(\*x == 3\) THEN GOTO \d | ||
IF !\(\(signed int \*\)\(void \*\)0 == \(\(signed int \*\)NULL\)\) THEN GOTO \d | ||
tmp_if_expr = \*\(\(signed int \*\)\(void \*\)0\) == 5 \? TRUE \: FALSE; | ||
tmp_if_expr\$\d = tmp_if_expr \? TRUE : FALSE; | ||
ASSUME tmp_if_expr\$\d | ||
// baz | ||
IF !\(z == \(\(signed int \*\)NULL\)\) THEN GOTO \d | ||
tmp_if_expr\$\d = \*z == 7 \? TRUE : FALSE; | ||
ASSUME tmp_if_expr\$\d | ||
// foo | ||
ASSUME \*tmp_cc\$\d > 0 | ||
ASSERT \*tmp_cc\$\d == 3 | ||
-- | ||
\[3\] file main\.c line 6 assertion: FAILURE | ||
-- | ||
ArenBabikian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Verification: | ||
This test checks support for a NULL pointer that is assigned to by | ||
a function (bar and baz). Both functions bar and baz are being replaced by | ||
their function contracts, while the calling function foo is being checked | ||
(by enforcing it's function contracts). |
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,36 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
int *z; | ||
|
||
void bar(int *x, int *y) __CPROVER_assigns(*x, *y) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3 && (y == NULL || *y == 5)) | ||
{ | ||
*x = 3; | ||
if(y != NULL) | ||
*y = 5; | ||
} | ||
|
||
void baz() __CPROVER_assigns(*z) __CPROVER_ensures(z == NULL || *z == 7) | ||
{ | ||
if(z != NULL) | ||
*z = 7; | ||
} | ||
|
||
void foo(int *x) __CPROVER_assigns(*x) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3) | ||
{ | ||
bar(x, NULL); | ||
*x = 3; | ||
z == NULL; | ||
baz(); | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
foo(&n); | ||
|
||
assert(n == 3); | ||
return 0; | ||
} |
19 changes: 19 additions & 0 deletions
19
regression/contracts/assigns_validity_pointer_02/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CORE | ||
main.c | ||
--enforce-contract foo | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
//^([foo\.1] line 15 assertion: FAILURE) | ||
// foo | ||
ASSUME \*tmp_cc\$\d > 0 | ||
ASSERT \*tmp_cc\$\d == 3 | ||
-- | ||
\[foo\.1\] line 24 assertion: FAILURE | ||
\[foo\.3\] line 27 assertion: FAILURE | ||
-- | ||
Verification: | ||
This test checks support for a NULL pointer that is assigned to by | ||
a function (bar and baz). The calling function foo is being checked | ||
(by enforcing it's function contracts). As for bar and baz, their | ||
function contracts are ot being considered for this test. |
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,33 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
int *z; | ||
|
||
void bar(int *x, int *y) __CPROVER_assigns(*x, *y) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3 && *y == 5) | ||
{ | ||
} | ||
|
||
void baz() __CPROVER_assigns(*z) __CPROVER_ensures(*z == 7) | ||
{ | ||
} | ||
|
||
void foo(int *x) __CPROVER_assigns(*x) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3) | ||
{ | ||
int *y; | ||
bar(x, y); | ||
assert(*y == 5); | ||
|
||
baz(); | ||
assert(*z == 7); | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
foo(&n); | ||
|
||
assert(n == 3); | ||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
regression/contracts/assigns_validity_pointer_03/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
KNOWNBUG | ||
main.c | ||
--enforce-contract foo --replace-call-with-contract bar --replace-call-with-contract baz | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
// bar | ||
ASSERT \*x > 0 | ||
IF !\(\*x == 3\) THEN GOTO \d | ||
tmp_if_expr = \*y == 5 \? TRUE \: FALSE; | ||
ASSUME tmp_if_expr | ||
// baz | ||
ASSUME \*z == 7 | ||
// foo | ||
ASSUME \*tmp_cc\$\d > 0 | ||
ASSERT \*tmp_cc\$\d == 3 | ||
-- | ||
-- | ||
Verification: | ||
This test checks support for an uninitialized pointer that is assigned to by | ||
a function (bar and baz). Both functions bar and baz are being replaced by | ||
their function contracts, while the calling function foo is being checked | ||
(by enforcing it's function contracts). | ||
|
||
Known Bug: | ||
Currently, there is a known issue with __CPROVER_w_ok(ptr, 0) such that it | ||
returns true if ptr is uninitialized. This is not the expected behavior, | ||
therefore, the outcome of this test case is currently incorrect. |
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,34 @@ | ||
#include <assert.h> | ||
ArenBabikian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <stddef.h> | ||
|
||
int *z; | ||
|
||
void bar(int *x, int *y) __CPROVER_assigns(*x, *y) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3 && *y == 5) | ||
{ | ||
} | ||
|
||
void baz() __CPROVER_assigns(*z) __CPROVER_ensures(*z == 7) | ||
{ | ||
} | ||
|
||
void foo(int *x) __CPROVER_assigns(*x) __CPROVER_requires(*x > 0) | ||
__CPROVER_ensures(*x == 3) | ||
{ | ||
int *y = malloc(sizeof(int)); | ||
bar(x, y); | ||
assert(*y == 5); | ||
|
||
z = malloc(sizeof(int)); | ||
baz(); | ||
assert(*z == 7); | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
foo(&n); | ||
|
||
assert(n == 3); | ||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
regression/contracts/assigns_validity_pointer_04/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CORE | ||
main.c | ||
--enforce-contract foo --replace-call-with-contract bar --replace-call-with-contract baz | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
// bar | ||
ASSERT \*x > 0 | ||
IF !\(\*x == 3\) THEN GOTO \d | ||
tmp_if_expr = \*y == 5 \? TRUE \: FALSE; | ||
ASSUME tmp_if_expr | ||
// baz | ||
ASSUME \*z == 7 | ||
// foo | ||
ASSUME \*tmp_cc\$\d > 0 | ||
ASSERT \*tmp_cc\$\d == 3 | ||
-- | ||
-- | ||
Verification: | ||
This test checks support for a malloced pointer that is assigned to by | ||
a function (bar and baz). Both functions bar and baz are being replaced by | ||
their function contracts, while the calling function foo is being checked | ||
(by enforcing it's function contracts). |
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
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.