Skip to content

Commit 873daa9

Browse files
authored
Merge pull request #5321 from danpoe/tests/pointer-primitives
Tests to check inconsistent assumptions involving __CPROVER_r_ok
2 parents ac0402f + b1be232 commit 873daa9

File tree

30 files changed

+360
-1
lines changed

30 files changed

+360
-1
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ add_subdirectory(goto-cc-file-local)
5656
add_subdirectory(linking-goto-binaries)
5757
add_subdirectory(symtab2gb)
5858
add_subdirectory(validate-trace-xml-schema)
59+
add_subdirectory(cbmc-primitives)
5960

6061
if(WITH_MEMORY_ANALYZER)
6162
add_subdirectory(snapshot-harness)

regression/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ DIRS = cbmc \
3333
solver-hardness \
3434
goto-ld \
3535
validate-trace-xml-schema \
36-
# Empty last line
36+
cbmc-primitives \
37+
# Empty last line
3738

3839
ifeq ($(OS),Windows_NT)
3940
detected_OS := Windows
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_test_pl_tests(
2+
"$<TARGET_FILE:cbmc>"
3+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
default: tests.log
2+
3+
test:
4+
@../test.pl -e -p -c ../../../src/cbmc/cbmc
5+
6+
tests.log: ../test.pl
7+
@../test.pl -e -p -c ../../../src/cbmc/cbmc
8+
9+
show:
10+
@for dir in *; do \
11+
if [ -d "$$dir" ]; then \
12+
vim -o "$$dir/*.c" "$$dir/*.out"; \
13+
fi; \
14+
done;
15+
16+
clean:
17+
find -name '*.out' -execdir $(RM) '{}' \;
18+
$(RM) tests.log
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p1;
7+
__CPROVER_assume(__CPROVER_r_ok(p1 - 1, 1));
8+
*p1;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KNOWNBUG
2+
main.c
3+
--pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Crashes during the flattening, issue #5328
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p;
7+
8+
{
9+
char c;
10+
p = &c;
11+
}
12+
13+
__CPROVER_assume(__CPROVER_r_ok(p, 1));
14+
assert(0); // fails
15+
*p; // succeeds
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FUTURE
2+
main.c
3+
--pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Tests that an inconsistent assumption involving a pointer to an out of scope
11+
variable and __CPROVER_r_ok() can be detected via assert(0). We use
12+
--no-simplify and --no-propagation to ensure that the case is not solved by the
13+
constant propagation and thus tests the constraint encoding.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Tests that an inconsistent assumption involving a pointer to an out of scope
11+
variable and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(1);
7+
free(p);
8+
9+
__CPROVER_assume(__CPROVER_r_ok(p, 1));
10+
assert(0); // fails
11+
*p; // succeeds
12+
}

0 commit comments

Comments
 (0)