-
Notifications
You must be signed in to change notification settings - Fork 285
Add support for conversion of pointer arithmetic expressions to new SMT backend. #6866
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
Changes from all commits
dad512c
4a40bca
1281a8d
1c82d4e
0e81d55
ee56b4f
34b2985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <stdint.h> | ||
|
|
||
| #define NULL (void *)0 | ||
|
|
||
| int main() | ||
| { | ||
| int32_t *a; | ||
| __CPROVER_assume(a != NULL); | ||
| int32_t *z = a + 2 * sizeof(int32_t); | ||
|
|
||
| __CPROVER_assert(a != z, "expected successful because of pointer arithmetic"); | ||
| __CPROVER_assert(a == z, "expected failure because of pointer arithmetic"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CORE | ||
| addition_compound_expr.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ expected successful because of pointer arithmetic: SUCCESS | ||
| \[main\.assertion\.2\] line \d+ expected failure because of pointer arithmetic: FAILURE | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This is testing the same thing as the test in addition_simple.desc, with the | ||
| difference being that the addition expression here is compound, containing a | ||
| more elaborate operand in the form of a multiplication containing a sizeof | ||
| operator. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #define NULL (void *)0 | ||
|
|
||
| int main() | ||
| { | ||
| int *x; | ||
| int *y = x + 1; | ||
| __CPROVER_assume(x != NULL); | ||
| __CPROVER_assume(y != NULL); | ||
|
|
||
| __CPROVER_assert(y == x, "expected false after pointer manipulation"); | ||
| __CPROVER_assert(y != x, "expected true"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| CORE | ||
| addition_simple.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ expected false after pointer manipulation: FAILURE | ||
| \[main\.assertion\.2\] line \d+ expected true: SUCCESS | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This is testing basic pointer arithmetic by adding by incrementing a pointer's | ||
| address and assigning that value to another pointer, then asserting that they | ||
| don't point to the same thing. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include <stdlib.h> | ||
| int main() | ||
| { | ||
| int *x = malloc(sizeof(int)); | ||
| int *y = x + 3; | ||
| int z = y - x; | ||
| __CPROVER_assert(y == x, "expected failure after pointer manipulation"); | ||
| __CPROVER_assert(z == 3, "expected successful after pointer manipulation"); | ||
| __CPROVER_assert(z != 3, "expected failure after pointer manipulation"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CORE | ||
| pointer_subtraction.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ expected failure after pointer manipulation: FAILURE | ||
| \[main\.assertion\.2\] line \d+ expected successful after pointer manipulation: SUCCESS | ||
| \[main\.assertion\.3\] line \d+ expected failure after pointer manipulation: FAILURE | ||
| z=3 | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This test is testing that the subtraction between two pointers (giving us the | ||
| increment between the two pointers) works as it should. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include <stdlib.h> | ||
| int main() | ||
| { | ||
| int *x = malloc(sizeof(int)); | ||
| float *y = x + 3; | ||
| int z = y - x; | ||
|
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. This subtraction is actually non-compiling code if I run it through |
||
| __CPROVER_assert(y == x, "expected failure after pointer manipulation"); | ||
| __CPROVER_assert(z == 3, "expected successful after pointer manipulation"); | ||
| __CPROVER_assert(z != 3, "expected failure after pointer manipulation"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| CORE | ||
| pointer_subtraction_diff_types.c | ||
| --trace | ||
| ^Reason: only pointers of the same object type can be subtracted. | ||
| ^EXIT=(134|127)$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This test is for making sure that we only subtract pointers with the | ||
| same underlying (base) type. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #define NULL (void *)0 | ||
|
|
||
| int main() | ||
| { | ||
| int *x; | ||
| unsigned int z; | ||
| __CPROVER_assume(z < 3); | ||
| __CPROVER_assume(z > 1); | ||
| int *y = x - z; | ||
| __CPROVER_assume(x != NULL); | ||
| __CPROVER_assume(y != NULL); | ||
|
|
||
| __CPROVER_assert(y == x, "expected failure after pointer manipulation"); | ||
| __CPROVER_assert(y != x, "expected success after pointer manipulation"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CORE | ||
| pointer_subtraction_unsigned.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ expected failure after pointer manipulation: FAILURE | ||
| \[main\.assertion\.2\] line \d+ expected success after pointer manipulation: SUCCESS | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| The test is similar to the one in `pointer_subtraction.desc`, but with different | ||
| types in the subtraction operands. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #define NULL (void *)0 | ||
|
|
||
| int main() | ||
| { | ||
| int *x; | ||
| int *y = x - 2; | ||
| __CPROVER_assume(x != NULL); | ||
| __CPROVER_assume(y != NULL); | ||
|
|
||
| __CPROVER_assert(y == x, "expected failure after pointer manipulation"); | ||
| __CPROVER_assert(y != x, "expected successful after pointer manipulation"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CORE | ||
| subtraction_simple.c | ||
| --trace | ||
| \[main\.assertion\.1\] line \d+ expected failure after pointer manipulation: FAILURE | ||
| \[main\.assertion\.2\] line \d+ expected successful after pointer manipulation: SUCCESS | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| -- | ||
| -- | ||
| This test is similar to the one in `addition_simple.desc`, but testing end-to-end | ||
| the conversion of a subtraction case of pointer arithmetic. |
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.
⛏️ I would prefer that one of the standard library definitions of
NULLwas used instead of defining it in the test, in order to avoid re-definition errors.