Skip to content

Commit 5d6d1ae

Browse files
authored
Merge pull request #5072 from martin-cs/feature/ai-history-use-cases
(Calling) context sensitivity in the abstract interpreter
2 parents c2d43f7 + fddd098 commit 5d6d1ae

File tree

21 files changed

+946
-99
lines changed

21 files changed

+946
-99
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+
3+
int f00(int x)
4+
{
5+
assert(x != 0);
6+
return 0;
7+
}
8+
9+
int main(int argc, char **argv)
10+
{
11+
int v = 0;
12+
v = f00(v);
13+
assert(v != 0);
14+
15+
return 0;
16+
}
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 --ahistorical --constants --one-domain-per-history
4+
\[main.assertion.1\] line 13 assertion v != 0: FAILURE \(if reachable\)
5+
\[f00.assertion.1\] line 5 assertion x != 0: FAILURE \(if reachable\)
6+
Summary: 0 pass, 2 fail if reachable, 0 unknown
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
--
12+
Tests the full AI configuration tuple AI/history/domain/storage
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int f00(int x)
4+
{
5+
assert(x != 0);
6+
return 0;
7+
}
8+
9+
int main(int argc, char **argv)
10+
{
11+
int v = 0;
12+
v = f00(v);
13+
assert(v != 0);
14+
15+
return 0;
16+
}
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 --ahistorical --constants --one-domain-per-location
4+
\[main.assertion.1\] line 13 assertion v != 0: FAILURE \(if reachable\)
5+
\[f00.assertion.1\] line 5 assertion x != 0: FAILURE \(if reachable\)
6+
Summary: 0 pass, 2 fail if reachable, 0 unknown
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
--
12+
Tests the full AI configuration tuple AI/history/domain/storage
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.

0 commit comments

Comments
 (0)