Skip to content

Selective modelling of volatile variables #5374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/goto-instrument/nondet-volatile-03/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CORE
test.c
--nondet-volatile-variable x
^Invalid User Input$
given name x does not represent a volatile variable with static lifetime$
symbol `x` does not represent a volatile variable with static lifetime$
^EXIT=1$
^SIGNAL=0$
--
Expand Down
10 changes: 10 additions & 0 deletions regression/goto-instrument/nondet-volatile-04/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <assert.h>

volatile int x;
int y;

void main()
{
y = x;
assert(x == y);
}
9 changes: 9 additions & 0 deletions regression/goto-instrument/nondet-volatile-04/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
test.c
--nondet-volatile
^\[main.assertion.1\] line \d+ assertion x == y: FAILURE$
^EXIT=10$
^SIGNAL=0$
--
--
Check interaction between a volatile and a non-volatile variable
20 changes: 20 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-01/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <assert.h>

volatile int a;
volatile int b;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one of these should have a regression test involving the interaction with non-volatile variables; E.g.

volatile int x;
int y = x;
assert(x == y); // fails because volatile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


int model()
{
int value;
__CPROVER_assume(value >= 0);
return value;
}

void main()
{
assert(a == 0);

assert(b >= 0);
assert(b == 0);
assert(b != 0);
}
12 changes: 12 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
test.c
--nondet-volatile-model b:model
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS
\[main.assertion.2\] line \d+ assertion b >= 0: SUCCESS
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE
^EXIT=10$
^SIGNAL=0$
--
--
Checks that the read from b is modelled via the given model
25 changes: 25 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-02/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <assert.h>

volatile int a;
volatile int b;
volatile int c;

int model()
{
int value;
__CPROVER_assume(value >= 0);
return value;
}

void main()
{
assert(a == 0);

assert(b >= 0);
assert(b == 0);
assert(b != 0);

assert(c >= 0);
assert(c == 0);
assert(c != 0);
}
16 changes: 16 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-02/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CORE
test.c
--nondet-volatile-variable b --nondet-volatile-model c:model
\[main.assertion.1\] line \d+ assertion a == 0: SUCCESS
\[main.assertion.2\] line \d+ assertion b >= 0: FAILURE
\[main.assertion.3\] line \d+ assertion b == 0: FAILURE
\[main.assertion.4\] line \d+ assertion b != 0: FAILURE
\[main.assertion.5\] line \d+ assertion c >= 0: SUCCESS
\[main.assertion.6\] line \d+ assertion c == 0: FAILURE
\[main.assertion.7\] line \d+ assertion c != 0: FAILURE
^EXIT=10$
^SIGNAL=0$
--
--
Checks that both options for selectively havocking/modelling volatile reads can
be used together
20 changes: 20 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-03/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <assert.h>

volatile int a;
volatile int b;

int model_a()
{
return 1;
}

int model_b()
{
return 2;
}

void main()
{
int result = a + b;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, does this work if the global is read via volatile pointer? (I'm assuming no, just for clarification).

Copy link
Contributor Author

@danpoe danpoe Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right, it currently only works for direct variable reads.

(One could also mark a pointer as nondet, in which case the pointer dereferences would be nondet as well. Though when --pointer-check would be enabled it would fail.)

assert(result == 3);
}
11 changes: 11 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-03/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
test.c
--nondet-volatile-model a:model_a --nondet-volatile-model b:model_b
\[main.assertion.1\] line \d+ assertion result == 3: SUCCESS
^EXIT=0$
^SIGNAL=0$
VERIFICATION SUCCESSFUL
--
--
Checks that two volatile reads in the same expression can both be modelled by
given functions
13 changes: 13 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-04/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <assert.h>

volatile int a;

float model()
{
return 1;
}

void main()
{
a;
}
11 changes: 11 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-04/test1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
test.c
--nondet-volatile-model a:model
^Invalid User Input$
return type of model .* is not compatible with the type of the modelled variable
^EXIT=1$
^SIGNAL=0$
--
--
Check that the command line typechecking reports when a model with a return type
that is incompatible with the type of the modelled variable is given
11 changes: 11 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-04/test2.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
test.c
--nondet-volatile-model a:non_existing_model
^Invalid User Input$
given model name .* not found in symbol table
^EXIT=1$
^SIGNAL=0$
--
--
Check that the command line typechecking reports when a given model for a
variable cannot be found
18 changes: 18 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-05/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <assert.h>

volatile int a;

int model_a()
{
return 1;
}

int model_b()
{
return 2;
}

void main()
{
a;
}
11 changes: 11 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-05/test1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
test.c
--nondet-volatile-model a:model_a --nondet-volatile-model a:model_b
^Invalid User Input$
conflicting models for variable
^EXIT=1$
^SIGNAL=0$
--
--
Check that the command line typechecking reports when two conflicting models are
given for a variable
11 changes: 11 additions & 0 deletions regression/goto-instrument/nondet-volatile-model-05/test2.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
test.c
--nondet-volatile-model a:model_a --nondet-volatile-variable a
^Invalid User Input$
conflicting options for variable
^EXIT=1$
^SIGNAL=0$
--
--
Check that the command line typechecking reports when conflicting options are
given for a variable
Loading