-
Notifications
You must be signed in to change notification settings - Fork 274
Adds support for struct members in history variables #6277
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
feliperodri
merged 2 commits into
diffblue:develop
from
feliperodri:struct-members-history
Aug 7, 2021
Merged
Changes from all commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdlib.h> | ||
|
||
struct pair | ||
{ | ||
int x; | ||
int y; | ||
}; | ||
|
||
void foo(struct pair *p) __CPROVER_assigns(p->y) | ||
__CPROVER_ensures(p->y == __CPROVER_old(p->y) + 5) | ||
{ | ||
p->y = p->y + 5; | ||
} | ||
|
||
int main() | ||
{ | ||
struct pair *p = malloc(sizeof(*p)); | ||
p->x = 2; | ||
p->y = 2; | ||
foo(p); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
main.c | ||
--enforce-all-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS$ | ||
^\[foo.\d+\] line \d+ Check that p\-\>y is assignable\: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test checks that history variables are supported for struct members. | ||
By using the --enforce-all-contracts flag, the post-condition (which contains | ||
the history variable) is asserted. In this case, this assertion should pass. |
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,50 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
struct pair | ||
{ | ||
int x; | ||
int *y; | ||
}; | ||
|
||
int z = 5; | ||
int w[10] = {0}; | ||
|
||
void foo(struct pair *p) __CPROVER_assigns(*(p->y), z) | ||
__CPROVER_ensures(*(p->y) == __CPROVER_old(*(p->y)) + __CPROVER_old(z)) | ||
{ | ||
*(p->y) = *(p->y) + z; | ||
z = 10; | ||
} | ||
|
||
void bar(struct pair *p) __CPROVER_assigns(p->y) | ||
__CPROVER_ensures(p->y == __CPROVER_old(p->y) + 5) | ||
{ | ||
p->y = (p->y + 5); | ||
} | ||
|
||
void baz(struct pair p) __CPROVER_assigns(p) | ||
__CPROVER_ensures(p == __CPROVER_old(p)) | ||
{ | ||
struct pair pp = p; | ||
struct pair empty = {0}; | ||
p = empty; | ||
p = pp; | ||
} | ||
|
||
int main() | ||
{ | ||
struct pair *p = malloc(sizeof(*p)); | ||
p->y = malloc(sizeof(*(p->y))); | ||
p->x = 2; | ||
*(p->y) = 2; | ||
foo(p); | ||
assert(*(p->y) == 7); | ||
p->y = w; | ||
w[5] = -1; | ||
bar(p); | ||
assert(*(p->y) == -1); | ||
baz(*p); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CORE | ||
main.c | ||
--enforce-all-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause\: SUCCESS$ | ||
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause\: SUCCESS$ | ||
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause\: SUCCESS$ | ||
^\[bar.\d+\] line \d+ Check that p\-\>y is assignable\: SUCCESS$ | ||
^\[baz.\d+\] line \d+ Check that pp is assignable\: SUCCESS$ | ||
^\[baz.\d+\] line \d+ Check that empty is assignable\: SUCCESS$ | ||
^\[baz.\d+\] line \d+ Check that p is assignable\: SUCCESS$ | ||
^\[baz.\d+\] line \d+ Check that p is assignable\: SUCCESS$ | ||
^\[foo.\d+\] line \d+ Check that \*p\-\>y is assignable\: SUCCESS$ | ||
^\[foo.\d+\] line \d+ Check that z is assignable\: SUCCESS$ | ||
^\[main.assertion.\d+\] line \d+ assertion \*\(p\-\>y\) == 7\: SUCCESS$ | ||
^\[main.assertion.\d+\] line \d+ assertion \*\(p\-\>y\) == -1\: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test checks that history variables are supported for structs, symbols, and | ||
struct members. By using the --enforce-all-contracts flag, the postcondition | ||
(with history variable) is asserted. In this case, this assertion should pass. |
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 @@ | ||
#include <stdlib.h> | ||
|
||
struct pair | ||
{ | ||
int x; | ||
int y; | ||
}; | ||
|
||
void foo(struct pair *p) __CPROVER_assigns(p->y) | ||
__CPROVER_ensures((p != NULL) == > (p->y == __CPROVER_old(p->y) + 5)) | ||
__CPROVER_ensures((p == NULL) == > (p->y == __CPROVER_old(p->y))) | ||
{ | ||
if(p != NULL) | ||
p->y = p->y + 5; | ||
} | ||
|
||
int main() | ||
{ | ||
struct pair *p = NULL; | ||
foo(p); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
KNOWNBUG | ||
main.c | ||
--enforce-all-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\[postcondition.\d+\] Check ensures clause\: SUCCESS$ | ||
^\[foo.\d+\] line \d+ Check that p\-\>y is assignable\: SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test checks that history variables handle NULL pointers. | ||
History variables currently do not check for nullness while | ||
storing values of objects, which may lead to NULL pointer dereferences. |
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,24 @@ | ||
#include <stdlib.h> | ||
|
||
struct pair | ||
{ | ||
int x; | ||
int y; | ||
}; | ||
|
||
void foo(struct pair *p) __CPROVER_requires(p != NULL) __CPROVER_assigns(p->y) | ||
__CPROVER_ensures(p->y == __CPROVER_old(p->y) + 5) | ||
{ | ||
p->y = p->y + 5; | ||
} | ||
|
||
int main() | ||
{ | ||
struct pair *p = malloc(sizeof(*p)); | ||
p->x = 2; | ||
p->y = 2; | ||
foo(p); | ||
assert(p->y != 7); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CORE | ||
main.c | ||
--replace-all-calls-with-contracts | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^\[precondition.\d+\] file main.c line \d+ Check requires clause\: SUCCESS$ | ||
^\[main.assertion.\d+\] line \d+ assertion p\-\>y \!\= 7\: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
This test checks that history variables are supported for struct members. | ||
By using the --replace-all-calls-with-contracts flag, the assertion in | ||
main should consider the ensures clause (with old value). In this case, | ||
this assertion should fail. |
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.