-
Notifications
You must be signed in to change notification settings - Fork 277
Fix for the handling of constant arrays and members of structs being marked nondet. #1654
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#define NULL 0 | ||
|
||
int x; | ||
int y = 23; | ||
const int z = 23; | ||
const int array[] = { 5, 6, 7, 8}; | ||
|
||
struct s { int x; }; | ||
struct s s1; | ||
struct s s2 = { 23 }; | ||
const struct s s3 = { 23 }; | ||
|
||
struct t { int x; const int y; }; | ||
struct t t1; | ||
struct t t2 = { 23, 23 }; | ||
const struct t t3 = { 23, 23 }; | ||
|
||
struct u { const int x; }; | ||
struct u u1; | ||
struct u u2 = { 23 }; | ||
const struct u u3 = { 23 }; | ||
|
||
struct list { const int datum; struct list * next; }; | ||
|
||
// The point of this is that cbmc needs to correctly handle | ||
// the embedded datum int the nested struct which is const, | ||
// while not falling into infinite recursion from the | ||
// recursive field. | ||
struct another_list { | ||
struct a_list { | ||
struct a_list * next; | ||
const int datum; | ||
} embedded; | ||
int a; | ||
}; | ||
|
||
struct contains_pointer { int x; int *p; }; | ||
// const int *p : declare p as pointer to const int | ||
struct contains_pointer_to_const { int x; const int *p; }; | ||
// int * const p : declare p as const pointer to int | ||
struct contains_constant_pointer { int x; int * const p; }; | ||
// this should cause a bug | ||
struct contains_pointer_to_const_point { int x; int * y; int * const p; }; | ||
|
||
struct contains_pointer a[3] = { {23, &x}, {23, &x}, {23, &x} }; | ||
struct contains_constant_pointer b[3] = { {23, &y}, {23, &y}, {23, &y} }; | ||
struct contains_pointer_to_const c[3] = { {23, &z}, {23, &z}, {23, &z} }; | ||
struct contains_pointer_to_const_point d[3]= { {23, &y, &z}, {23, &y, &z}, {23, &y, &z} }; | ||
|
||
struct list node = {10, NULL}; | ||
|
||
struct another_list one_list = {{10, NULL}, 5}; | ||
|
||
typedef int Int; | ||
typedef const int Const_Int; | ||
|
||
const Int p = 23; | ||
Const_Int q = 23; | ||
|
||
|
||
#include <assert.h> | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
struct list linked_list = {5, &node}; | ||
|
||
/* Pass normally but fail with nondet-static */ | ||
assert(x == 0); | ||
assert(y == 23); | ||
assert(s1.x == 0); | ||
assert(s2.x == 23); | ||
assert(a[0].x == 23); | ||
assert(a[0].p == &x); | ||
assert(c[2].x == 23); | ||
assert(c[2].p == &z); | ||
|
||
/* Should still pass */ | ||
assert(z == 23); | ||
assert(s3.x == 23); | ||
assert(t1.y == 0); | ||
assert(t2.y == 23); | ||
assert(t3.x == 23); | ||
assert(t3.y == 23); | ||
assert(u1.x == 0); | ||
assert(u2.x == 23); | ||
assert(u3.x == 23); | ||
assert(p == 23); | ||
assert(q == 23); | ||
assert(t1.x == 0); | ||
assert(t2.x == 23); | ||
assert(b[1].x == 23); | ||
assert(b[1].p == &y); | ||
assert(d[1].y == &y); | ||
assert(linked_list.datum == 5); | ||
assert(linked_list.next->datum == 10); | ||
assert(one_list.a == 5); | ||
assert(array[1] == 6); | ||
|
||
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,36 @@ | ||
CORE | ||
main.c | ||
--nondet-static | ||
^VERIFICATION FAILED$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion x == 0: FAILURE | ||
assertion y == 23: FAILURE | ||
assertion s1.x == 0: FAILURE | ||
assertion s2.x == 23: FAILURE | ||
assertion a\[0\].x == 23: FAILURE | ||
assertion a\[0\].p == &x: FAILURE | ||
assertion c\[2\].x == 23: FAILURE | ||
assertion c\[2\].p == &z: FAILURE | ||
assertion z == 23: SUCCESS | ||
assertion s3.x == 23: SUCCESS | ||
assertion t1.y == 0: SUCCESS | ||
assertion t2.y == 23: SUCCESS | ||
assertion t3.x == 23: SUCCESS | ||
assertion t3.y == 23: SUCCESS | ||
assertion u1.x == 0: SUCCESS | ||
assertion u2.x == 23: SUCCESS | ||
assertion u3.x == 23: SUCCESS | ||
assertion p == 23: SUCCESS | ||
assertion q == 23: SUCCESS | ||
assertion t1.x == 0: SUCCESS | ||
assertion t2.x == 23: SUCCESS | ||
assertion b\[1\].x == 23: SUCCESS | ||
assertion b\[1\].p == &y: SUCCESS | ||
assertion d\[1\].y == &y: SUCCESS | ||
assertion linked_list.datum == 5: SUCCESS | ||
assertion linked_list.next->datum == 10: SUCCESS | ||
assertion one_list.a == 5: SUCCESS | ||
assertion array\[1\] == 6: SUCCESS | ||
-- | ||
-- |
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
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.
Please also check SIGNALS and exit codes as other tests commonly do.