Skip to content

Commit 38ca41f

Browse files
Remi Delmasfeliperodri
authored andcommitted
Adding more tests on what expressions shall be accepted/rejected in assigns clauses.
1 parent ef7e94d commit 38ca41f

File tree

33 files changed

+545
-1
lines changed

33 files changed

+545
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
5+
int foo(int *x) __CPROVER_assigns(&x)
6+
{
7+
*x = 0;
8+
return 0;
9+
}
10+
11+
int main()
12+
{
13+
int x;
14+
foo(&x);
15+
return 0;
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo
4+
^EXIT=(1|64)$
5+
^SIGNAL=0$
6+
^.*error: illegal target in assigns clause$
7+
^CONVERSION ERROR$
8+
--
9+
--
10+
Check that address_of expressions are rejected in assigns clauses.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
5+
int foo(bool a, int *x, int *y, int *z) __CPROVER_assigns(*(a ? x : y))
6+
{
7+
if(a)
8+
*x = 0; // must pass
9+
else
10+
*y = 0; // must pass
11+
return 0;
12+
}
13+
14+
int main()
15+
{
16+
bool a;
17+
int x;
18+
int y;
19+
int z;
20+
21+
foo(a, &x, &y, &z);
22+
return 0;
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main.c function foo
7+
^\[foo.1] line \d+ Check that \*x is assignable: SUCCESS$
8+
^\[foo.2] line \d+ Check that \*y is assignable: SUCCESS$
9+
^VERIFICATION SUCCESSFUL$
10+
--
11+
--
12+
Check that Elvis operator expressions '*(cond ? if_true : if_false)' are accepted in assigns clauses and work as expected.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
5+
int foo(bool a, int *x, int *y, int *z) __CPROVER_assigns(*(a ? x : y))
6+
{
7+
if(a)
8+
*x = 0; // must pass
9+
else
10+
*z = 0; // must fail
11+
return 0;
12+
}
13+
14+
int main()
15+
{
16+
bool a;
17+
int x;
18+
int y;
19+
int z;
20+
21+
foo(a, &x, &y, &z);
22+
return 0;
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
main.c function foo
7+
^\[foo.1] line \d+ Check that \*x is assignable: SUCCESS$
8+
^\[foo.2] line \d+ Check that \*z is assignable: FAILURE$
9+
^VERIFICATION FAILED$
10+
--
11+
--
12+
Check that Elvis operator expressions '*(cond ? if_true : if_false)' are accepted in assigns clauses and work as expected.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
5+
int foo(bool a, int *x, int *y, int *z) __CPROVER_assigns(*(a ? x : y))
6+
{
7+
if(a)
8+
{
9+
*x = 0; // must pass
10+
}
11+
else
12+
{
13+
// must pass because in the context of main, this branch is dead
14+
// so foo never attempts to write to *z.
15+
*z = 0;
16+
}
17+
return 0;
18+
}
19+
20+
int main()
21+
{
22+
bool a;
23+
int x;
24+
int y;
25+
int z;
26+
27+
foo(true, &x, &y, &z);
28+
return 0;
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
main.c function foo
7+
^\[foo.1] line \d+ Check that \*x is assignable: SUCCESS$
8+
^\[foo.2] line \d+ Check that \*z is assignable: SUCCESS$
9+
^VERIFICATION SUCCESSFUL$
10+
--
11+
--
12+
Check that Elvis operator expressions '*(cond ? if_true : if_false)' are accepted in assigns clauses.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
5+
int foo(bool a, int *x, long long *y) __CPROVER_assigns(*(a ? x : y))
6+
{
7+
if(a)
8+
{
9+
*x = 0;
10+
}
11+
else
12+
{
13+
*y = 0;
14+
}
15+
return 0;
16+
}
17+
18+
int main()
19+
{
20+
bool a;
21+
int x;
22+
long y;
23+
24+
foo(true, &x, &y);
25+
return 0;
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo
4+
^EXIT=(1|64)$
5+
^SIGNAL=0$
6+
^.*error: void-typed targets not permitted$
7+
--
8+
--
9+
Check that Elvis operator expressions '*(cond ? if_true : if_false)' with different types in true and false branches are rejected.

0 commit comments

Comments
 (0)