Skip to content

Commit c7067b0

Browse files
authored
Merge pull request #5374 from danpoe/feature/selective-modelling-of-volatile-variables
Selective modelling of volatile variables
2 parents 8b604a7 + d8c6441 commit c7067b0

File tree

17 files changed

+517
-83
lines changed

17 files changed

+517
-83
lines changed

regression/goto-instrument/nondet-volatile-03/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
test.c
33
--nondet-volatile-variable x
44
^Invalid User Input$
5-
given name x does not represent a volatile variable with static lifetime$
5+
symbol `x` does not represent a volatile variable with static lifetime$
66
^EXIT=1$
77
^SIGNAL=0$
88
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
volatile int x;
4+
int y;
5+
6+
void main()
7+
{
8+
y = x;
9+
assert(x == y);
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.c
3+
--nondet-volatile
4+
^\[main.assertion.1\] line \d+ assertion x == y: FAILURE$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Check interaction between a volatile and a non-volatile variable
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
volatile int a;
4+
volatile int b;
5+
6+
int model()
7+
{
8+
int value;
9+
__CPROVER_assume(value >= 0);
10+
return value;
11+
}
12+
13+
void main()
14+
{
15+
assert(a == 0);
16+
17+
assert(b >= 0);
18+
assert(b == 0);
19+
assert(b != 0);
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--nondet-volatile-model b:model
4+
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS
5+
\[main.assertion.2\] line \d+ assertion b >= 0: SUCCESS
6+
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE
7+
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE
8+
^EXIT=10$
9+
^SIGNAL=0$
10+
--
11+
--
12+
Checks that the read from b is modelled via the given model
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <assert.h>
2+
3+
volatile int a;
4+
volatile int b;
5+
volatile int c;
6+
7+
int model()
8+
{
9+
int value;
10+
__CPROVER_assume(value >= 0);
11+
return value;
12+
}
13+
14+
void main()
15+
{
16+
assert(a == 0);
17+
18+
assert(b >= 0);
19+
assert(b == 0);
20+
assert(b != 0);
21+
22+
assert(c >= 0);
23+
assert(c == 0);
24+
assert(c != 0);
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test.c
3+
--nondet-volatile-variable b --nondet-volatile-model c:model
4+
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS
5+
\[main.assertion.2\] line \d+ assertion b >= 0: FAILURE
6+
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE
7+
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE
8+
\[main.assertion.5\] line \d+ assertion c >= 0: SUCCESS
9+
\[main.assertion.6\] line \d+ assertion c == 0: FAILURE
10+
\[main.assertion.7\] line \d+ assertion c != 0: FAILURE
11+
^EXIT=10$
12+
^SIGNAL=0$
13+
--
14+
--
15+
Checks that both options for selectively havocking/modelling volatile reads can
16+
be used together
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
volatile int a;
4+
volatile int b;
5+
6+
int model_a()
7+
{
8+
return 1;
9+
}
10+
11+
int model_b()
12+
{
13+
return 2;
14+
}
15+
16+
void main()
17+
{
18+
int result = a + b;
19+
assert(result == 3);
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--nondet-volatile-model a:model_a --nondet-volatile-model b:model_b
4+
\[main.assertion.1\] line \d+ assertion result == 3: SUCCESS
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
VERIFICATION SUCCESSFUL
8+
--
9+
--
10+
Checks that two volatile reads in the same expression can both be modelled by
11+
given functions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
volatile int a;
4+
5+
float model()
6+
{
7+
return 1;
8+
}
9+
10+
void main()
11+
{
12+
a;
13+
}

0 commit comments

Comments
 (0)