Skip to content

Commit 63da579

Browse files
authored
Merge pull request #7289 from qinheping/crangler
Crangler: Add three tests for annotating function contracts
2 parents e42ec8c + b6a66c6 commit 63da579

File tree

9 files changed

+120
-0
lines changed

9 files changed

+120
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int f1(int *x1)
2+
{
3+
return *x1 + 1;
4+
}
5+
6+
int main()
7+
{
8+
int p;
9+
__CPROVER_assume(p > 1 && p < 10000);
10+
f1(&p);
11+
12+
return 0;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.json
3+
4+
\_\_CPROVER\_requires.*\_\_CPROVER\_requires.*\_\_CPROVER_ensures
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Annotate function contracts to function f1.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"sources": [
3+
"main.c"
4+
],
5+
"functions": [
6+
{
7+
"f1": [
8+
"requires *x1 > 1",
9+
"requires *x1 < 10000",
10+
"ensures __CPROVER_return_value == *x1 + 1"
11+
]
12+
}
13+
],
14+
"output": "stdout"
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int foo(int *x)
2+
{
3+
*x = *x + 0;
4+
return *x + 5;
5+
}
6+
7+
int main()
8+
{
9+
int n = 4;
10+
n = foo(&n);
11+
12+
return 0;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.json
3+
4+
\_\_CPROVER\_assigns.*_\_CPROVER_ensures
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Annotate function contracts to function foo.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"sources": [
3+
"main.c"
4+
],
5+
"functions": [
6+
{
7+
"foo": [
8+
"assigns *x",
9+
"ensures __CPROVER_return_value == *x + 5"
10+
]
11+
}
12+
],
13+
"output": "stdout"
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int f1(int *x1)
2+
{
3+
return f2(x1) + 1;
4+
}
5+
6+
int f2(int *x2)
7+
{
8+
return *x2 + 1;
9+
}
10+
11+
int main()
12+
{
13+
int p;
14+
__CPROVER_assume(p > 1 && p < 10000);
15+
f1(&p);
16+
17+
return 0;
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.json
3+
4+
activate-multi-line-match
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
int f1\(int \*x1\)\n \_\_CPROVER\_requires\(\*x1\>1\&\&\*x1\<10000\) \_\_CPROVER\_ensures\(.*\=\=\*x1\+2\)
8+
int f2\(int \*x2\)\n \_\_CPROVER\_requires\(\*x2\>1\&\&\*x2\<10000\) \_\_CPROVER\_ensures\(.*\=\=\*x2\+1\)
9+
--
10+
--
11+
Annotate function contracts to functions f1 and f2.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"sources": [
3+
"main.c"
4+
],
5+
"functions": [
6+
{
7+
"f1": [
8+
"requires *x1 > 1 && *x1 < 10000",
9+
"ensures __CPROVER_return_value == *x1 + 2"
10+
],
11+
"f2": [
12+
"requires *x2 > 1 && *x2 < 10000",
13+
"ensures __CPROVER_return_value == *x2 + 1"
14+
]
15+
}
16+
],
17+
"output": "stdout"
18+
}

0 commit comments

Comments
 (0)