Skip to content

Commit 349b710

Browse files
martinmartin
authored andcommitted
Tests for call stack history in the abstract interpreter
The existing --constants domain has some in-built handling of recursion by proactively merging things which means that some of these do not quite work. Which is annoying.
1 parent 029c4b9 commit 349b710

File tree

8 files changed

+137
-0
lines changed

8 files changed

+137
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
3+
unsigned fib(unsigned x)
4+
{
5+
switch(x)
6+
{
7+
case 0:
8+
return 0;
9+
break;
10+
case 1:
11+
return 1;
12+
break;
13+
default:
14+
return fib(x - 1) + fib(x - 2);
15+
break;
16+
}
17+
}
18+
19+
int main(int argc, char **argv)
20+
{
21+
unsigned v = fib(7);
22+
assert(v == 13); // Requires context sensitivity to handle with constants
23+
24+
unsigned w = fib(9);
25+
assert(w == 24); // Requires location, not just function tracking
26+
27+
return 0;
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
--verify --recursive-interprocedural --call-stack 10 --constants --one-domain-per-history
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion v == 13: SUCCESS$
7+
^\[main.assertion.2\] .* assertion w == 24: SUCCESS$
8+
--
9+
^warning: ignoring
10+
--
11+
This should be possible just tracking constants and calling stacks.
12+
At the moment the --constants domain can't do it due to the way it proactively merges to handle recursion.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
int negate(int x)
4+
{
5+
return -x;
6+
}
7+
8+
int main(int argc, char **argv)
9+
{
10+
int x = 23;
11+
int nx = negate(x);
12+
int nnx = negate(nx);
13+
14+
assert(x == nnx);
15+
16+
return 0;
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--verify --recursive-interprocedural --call-stack 0 --constants --one-domain-per-history
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion x == nnx: SUCCESS$
7+
--
8+
^warning: ignoring
9+
--
10+
A simple test of call stacks and context sensitivity. Merging calling context with contexts will give a failure.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <assert.h>
2+
3+
int step(int x)
4+
{
5+
if(x <= 0)
6+
{
7+
return 0;
8+
}
9+
else
10+
{
11+
return x + step(x - 1);
12+
}
13+
}
14+
15+
int main(int argc, char **argv)
16+
{
17+
int x = 5;
18+
int res = step(x);
19+
20+
assert(res == 15);
21+
22+
return 0;
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--verify --recursive-interprocedural --call-stack 10 --constants --one-domain-per-history
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion res == 15: SUCCESS$
7+
--
8+
^warning: ignoring
9+
--
10+
This should be possible just tracking constants and calling stacks.
11+
At the moment the --constants domain can't do it due to the way it proactively merges to handle recursion.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int step(int x)
4+
{
5+
if(x == 0)
6+
{
7+
assert(x == 0);
8+
return 0;
9+
}
10+
else
11+
{
12+
return step(x - 1);
13+
}
14+
}
15+
16+
int main(int argc, char **argv)
17+
{
18+
int orig = 20;
19+
int res = step(orig);
20+
21+
assert(res == 0);
22+
23+
return 0;
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--verify --recursive-interprocedural --call-stack 10 --constants --one-domain-per-history
4+
^\[main.assertion.1\] .* assertion res == 0: SUCCESS$
5+
^\[step.assertion.1\] .* assertion x == 0: SUCCESS$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Tests the interaction of call stacks and recursion.
12+

0 commit comments

Comments
 (0)