Skip to content

Commit 5186d6f

Browse files
authored
Merge pull request #6923 from NlightNFotis/pointer_casting_tests
Pointer casting regression tests for new SMT backend
2 parents 91eac8a + 126cfff commit 5186d6f

10 files changed

+132
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
4+
int main()
5+
{
6+
uint32_t input;
7+
uint32_t original = input;
8+
uint8_t *ptr = (uint8_t *)(&input);
9+
assert(*ptr == 0); // falsifiable
10+
*ptr = ~(*ptr);
11+
assert(input != original); // valid
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
byte_extract_issue.c
3+
--trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
--
7+
Reached unimplemented Generation of SMT formula for byte extract expression: byte_extract_little_endian
8+
--
9+
This test is here to document our lack of support for byte_extract_little_endian
10+
in the pointers support for the new SMT backend.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#include <stdint.h>
3+
4+
int main()
5+
{
6+
uint32_t x = 0;
7+
uint8_t *ptr = (uint8_t *)(&x);
8+
int offset;
9+
__CPROVER_assume(offset >= 0 && offset < 4);
10+
*(ptr + offset) = 1;
11+
assert(x != 256);
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
byte_update_issue.c
3+
--trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
--
7+
Reached unimplemented Generation of SMT formula for byte extract expression: byte_update_little_endian
8+
--
9+
This test is here to document our lack of support for byte_update_little_endian
10+
in the pointers support for the new SMT backend.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int main()
2+
{
3+
int *p = (int *)4;
4+
__CPROVER_allocated_memory(4, sizeof(int));
5+
6+
__CPROVER_assert(p == 4, "p == 4: expected success");
7+
__CPROVER_assert(p != 0, "p != 0: expected success");
8+
9+
p = (int *)0x1020304;
10+
__CPROVER_assert(p == 0x1020304, "p == 0x1020304: expected success");
11+
__CPROVER_assert(p != 0, "p != 0: expected success");
12+
__CPROVER_assert(p == 0, "p != 0: expected failure");
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
pointer_from_int.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ p == 4: expected success: SUCCESS
5+
\[main\.assertion\.2\] line \d+ p != 0: expected success: SUCCESS
6+
\[main\.assertion\.3\] line \d+ p == 0x1020304: expected success: SUCCESS
7+
\[main\.assertion\.4\] line \d+ p != 0: expected success: SUCCESS
8+
\[main\.assertion\.5\] line \d+ p != 0: expected failure: FAILURE
9+
^VERIFICATION FAILED$
10+
^EXIT=10$
11+
^SIGNAL=0$
12+
--
13+
--
14+
This test is covering basic conversion of pointer values to integers.
15+
It contains two such conversions, one of an integer in decimal form,
16+
and one of an integer in a hexadecimal form.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int f(int x)
2+
{
3+
void *p = (void *)x;
4+
int r = (int)p;
5+
return r;
6+
}
7+
8+
int main()
9+
{
10+
int a = f(5);
11+
__CPROVER_assert(a == 5, "a == 5: expected success");
12+
__CPROVER_assert(a != 5, "a != 5: expected failure");
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
pointer_round_trip.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ a == 5: expected success: SUCCESS
5+
\[main\.assertion\.2\] line \d+ a != 5: expected failure: FAILURE
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
11+
This test is testing an integer value round trip (int -> pointer -> int) test.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int cmp(const void *p1, const void *p2)
2+
{
3+
int x = *(int *)p1;
4+
int y = *(int *)p2;
5+
6+
return (x < y) ? -1 : ((x == y) ? 0 : 1);
7+
}
8+
9+
int main()
10+
{
11+
int a = 5;
12+
int b = 6;
13+
int c = 7;
14+
15+
__CPROVER_assert(cmp(&a, &b) == -1, "expected result == -1: success");
16+
__CPROVER_assert(cmp(&c, &b) == 1, "expected result == 1: success");
17+
__CPROVER_assert(cmp(&c, &c) == 0, "expected result == 0: success");
18+
__CPROVER_assert(cmp(&c, &c) == 1, "expected result == 1: failure");
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
pointer_to_int.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ expected result == -1: success: SUCCESS
5+
\[main\.assertion\.2\] line \d+ expected result == 1: success: SUCCESS
6+
\[main\.assertion\.3\] line \d+ expected result == 0: success: SUCCESS
7+
\[main\.assertion\.4\] line \d+ expected result == 1: failure: FAILURE
8+
^VERIFICATION FAILED$
9+
^EXIT=10$
10+
^SIGNAL=0$
11+
--
12+
--
13+
This test is covering basic conversion of casting of different pointer values,
14+
which are then dereferenced and used in the function. We are asserting against
15+
the result of the function, which cannot be right, unless the conversions
16+
work as they should.

0 commit comments

Comments
 (0)