-
Notifications
You must be signed in to change notification settings - Fork 284
Relational operators support for pointers in new SMT backend #6905
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
NlightNFotis
merged 4 commits into
diffblue:develop
from
NlightNFotis:relational_operators_pointer_support
Jun 9, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ebaabf9
Add implementation for pointers relational operators support
NlightNFotis 7094f98
Add two regression tests for pointer relational support
NlightNFotis 582fe78
Add unit tests for relational operators on pointers in new SMT backend
NlightNFotis 118b5b1
Add relational operators in assume context regression tests
NlightNFotis 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
27 changes: 27 additions & 0 deletions
27
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_assume.c
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,27 @@ | ||
| #include <stdlib.h> | ||
|
|
||
| int main() | ||
| { | ||
| int x; | ||
| int *y = &x; | ||
| int *z = &x; | ||
|
|
||
| if(x) | ||
| { | ||
| y++; | ||
| } | ||
| else | ||
| { | ||
| z++; | ||
| } | ||
|
|
||
| __CPROVER_assume(y >= z); | ||
| __CPROVER_assert(x != y, "x != y: expected successful"); | ||
| __CPROVER_assert(x == y, "x == y: expected failure"); | ||
|
|
||
| __CPROVER_assume(z >= x); | ||
|
|
||
| __CPROVER_assert(z >= x, "z >= x: expected successful"); | ||
| __CPROVER_assert(z <= y, "z <= y: expected successful"); | ||
| __CPROVER_assert(z <= x, "z <= x: expected failure"); | ||
| } |
14 changes: 14 additions & 0 deletions
14
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_assume.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,14 @@ | ||
| CORE | ||
| pointers_assume.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ x != y: expected successful: SUCCESS | ||
| \[main\.assertion\.2\] line \d+ x == y: expected failure: FAILURE | ||
| \[main\.assertion\.3\] line \d+ z >= x: expected successful: SUCCESS | ||
| \[main\.assertion\.4\] line \d+ z <= y: expected successful: SUCCESS | ||
| \[main\.assertion\.5\] line \d+ z <= x: expected failure: FAILURE | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This is testing basic pointer relational operator support for three objects | ||
| defined in the function's stack frame. |
19 changes: 19 additions & 0 deletions
19
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_stack_lessthan.c
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 @@ | ||
| #define NULL (void *)0 | ||
|
|
||
| int main() | ||
| { | ||
| int i = 12; | ||
| int *x = &i; | ||
| int *y = x + 1; | ||
| int *z = x - 1; | ||
|
|
||
| // Assertions on y's relation to x | ||
| __CPROVER_assert(y != x, "y != x: expected successful"); | ||
| __CPROVER_assert(y > x, "y > x: expected successful"); | ||
| __CPROVER_assert(y < x, "y < x: expected failure"); | ||
|
|
||
| // Assertions on z's relation to x | ||
| __CPROVER_assert(z != x, "z != x: expected successful"); | ||
| __CPROVER_assert(z > x, "z > x: expected failure"); | ||
| __CPROVER_assert(z < x, "z < x: expected success"); | ||
| } |
15 changes: 15 additions & 0 deletions
15
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_stack_lessthan.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,15 @@ | ||
| CORE | ||
| pointers_stack_lessthan.c | ||
| --trace | ||
| \[main\.assertion\.1] line \d+ y != x: expected successful: SUCCESS | ||
| \[main\.assertion\.2] line \d+ y > x: expected successful: SUCCESS | ||
| \[main\.assertion\.3] line \d+ y < x: expected failure: FAILURE | ||
| \[main\.assertion\.4] line \d+ z != x: expected successful: SUCCESS | ||
| \[main\.assertion\.5] line \d+ z > x: expected failure: FAILURE | ||
| \[main\.assertion\.6] line \d+ z < x: expected success: SUCCESS | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This is testing basic pointer relational operator support for three objects | ||
| defined in the function's stack frame. |
17 changes: 17 additions & 0 deletions
17
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_stack_malloc.c
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,17 @@ | ||
| #include <stdlib.h> | ||
|
|
||
| int main() | ||
| { | ||
| int *a = malloc(sizeof(int) * 5); | ||
|
|
||
| for(int i = 0; i < 5; i++) | ||
| *(a + i) = i; | ||
|
|
||
| for(int i = 0; i < 5; i++) | ||
| { | ||
| __CPROVER_assert(*(a + i) >= i, "*(a + i) >= i: expected successful"); | ||
| __CPROVER_assert(*(a + i) <= i, "*(a + i) <= i: expected successful"); | ||
| __CPROVER_assert(*(a + i) == i, "*(a + i) <= i: expected successful"); | ||
| __CPROVER_assert(*(a + i) != i, "*(a + i) <= i: expected failure"); | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
regression/cbmc-incr-smt2/pointers-relational-operators/pointers_stack_malloc.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,13 @@ | ||
| CORE | ||
| pointers_stack_malloc.c | ||
|
Contributor
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. ⛏️ Isn't |
||
| --trace | ||
| \[main\.assertion\.1\] line \d+ \*\(a \+ i\) >= i: expected successful: SUCCESS | ||
| \[main\.assertion\.2\] line \d+ \*\(a \+ i\) <= i: expected successful: SUCCESS | ||
| \[main\.assertion\.3\] line \d+ \*\(a \+ i\) <= i: expected successful: SUCCESS | ||
| \[main\.assertion\.4\] line \d+ \*\(a \+ i\) <= i: expected failure: FAILURE | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This is testing the support for relational operators as applied to pointer objects | ||
| backed by a malloc and initialised to some values. | ||
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
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.
ℹ️ This test is pretty close to running into the unimplemented array functionality. Adding
--no-array-field-sensitivityto cbmc will cause a failure. Also replacing the lastforloop using a non-det range for theivariable will do the same -No need to action this comment. I just wanted to make note of my findings into why this array using example works despite the unimplemented array functionality.