Skip to content

Commit 1157ad3

Browse files
committed
goto instrument loop unwinding with strategies
1 parent c8fa5be commit 1157ad3

File tree

59 files changed

+1207
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1207
-180
lines changed

regression/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DIRS = ansi-c cbmc cpp goto-instrument
1+
DIRS = ansi-c cbmc cpp goto-instrument goto-instrument-unwind
22

33
test:
44
$(foreach var,$(DIRS), $(MAKE) -C $(var) test || exit 1;)

regression/goto-instrument-unwind/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ tests.log: ../test.pl
2121
clean:
2222
@for dir in *; do \
2323
if [ -d "$$dir" ]; then \
24-
rm $$dir/*.txt $$dir/*.dot $$dir/*.gb $$dir/*.out; \
24+
rm -f $$dir/*.txt $$dir/*.dot $$dir/*.gb $$dir/*.out; \
2525
fi; \
26-
done;
26+
done;
27+
rm -f tests.log
2728

2829
show:
2930
@for dir in *; do \
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 10 --unwinding-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--unwind 9 --unwinding-assertions
4+
^SIGNAL=0$
5+
^VERIFICATION FAILED$
6+
--
7+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
int main()
3+
{
4+
int i;
5+
i = 0;
6+
do {
7+
i++;
8+
} while(i < 10);
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 10 --unwinding-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
assert(0);
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--unwind 10
4+
^SIGNAL=0$
5+
^VERIFICATION FAILED$
6+
--
7+
^warning: ignoring
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
assert(0);
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 9
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/goto-instrument-unwind/break-loop1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/break-loop2/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
100
3+
--unwind 100 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
assert(i==10);
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--unwind 5 --continue-as-loops
4+
^Unwinding loop.*iteration 5
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring
10+
^Unwinding loop.*iteration 6

regression/goto-instrument-unwind/continue-loop1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/continue-loop2/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
100
3+
--unwind 100 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
void f() {}
3+
4+
int main()
5+
{
6+
/**
7+
* This is a test case for the unwind operation of goto-instrument;
8+
* every loop will be unwound K times
9+
**/
10+
const unsigned K=10;
11+
12+
const unsigned n=100;
13+
unsigned c=0, i;
14+
15+
i=1;
16+
do
17+
{
18+
f();
19+
c++;
20+
i++;
21+
} while(i<=n);
22+
23+
unsigned eva=n;
24+
if(K<eva) eva=K;
25+
26+
__CPROVER_assert(c==eva, "do-while loop unwind (1)");
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
void f() {}
3+
4+
int main()
5+
{
6+
/**
7+
* This is a test case for the unwind operation of goto-instrument;
8+
* every loop will be unwound K times
9+
**/
10+
const unsigned K=100;
11+
12+
const unsigned n=10;
13+
unsigned c=0, i;
14+
15+
i=1;
16+
do
17+
{
18+
f();
19+
c++;
20+
i++;
21+
} while(i<=n);
22+
23+
unsigned eva=n;
24+
if(K<eva) eva=K;
25+
26+
__CPROVER_assert(c==eva, "do-while loop unwind (1)");
27+
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 100 --partial-loops
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/goto-instrument-unwind/empty-loop1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/empty-loop2/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
100
3+
--unwind 100 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/nested-loops1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/nested-loops2/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/simple-loop1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
10
3+
--unwind 10 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/simple-loop2/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
main.c
3-
100
3+
--unwind 100 --partial-loops
4+
^EXIT=0$
45
^SIGNAL=0$
56
^VERIFICATION SUCCESSFUL$
67
--

regression/goto-instrument-unwind/unwind-chain.sh

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@ goto_cc=$src/goto-cc/goto-cc
55
goto_instrument=$src/goto-instrument/goto-instrument
66
cbmc=$src/cbmc/cbmc
77

8-
function usage() {
9-
echo "Usage: chain unwind-num test_file.c"
10-
exit 1
11-
}
8+
name=${@:$#}
9+
name=${name%.c}
1210

13-
echo "Usage: process test_file.c to goto program"
14-
15-
if [ $# -eq 2 ]
16-
then
17-
unwind_num=$1
18-
name=`echo $2 | cut -d. -f1`
19-
echo $unwind_num
20-
echo $name
21-
else
22-
usage
23-
fi
11+
args=${@:1:$#-1}
2412

2513
$goto_cc -o $name.gb $name.c
26-
$goto_instrument $name.gb ${name}-unwound.gb --unwind $unwind_num
14+
$goto_instrument --show-goto-functions $name.gb
15+
$goto_instrument $args $name.gb ${name}-unwound.gb
16+
$goto_instrument --show-goto-functions ${name}-unwound.gb
2717
$cbmc ${name}-unwound.gb
18+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 10 --unwinding-assertions --log -
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {
6+
int j;
7+
for(j = 0; j < 10; j++) {
8+
int k;
9+
k = 0;
10+
while(k < 10)
11+
{
12+
k++;
13+
}
14+
}
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 5 --unwindset-file unwindset.input --unwinding-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main.0:10,main.1:10,main.2:10
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
int main()
3+
{
4+
int i;
5+
for(i = 0; i < 10; i++) {}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwind 9 --unwindset main.0:10 --unwinding-assertions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
int main()
3+
{
4+
int i;
5+
6+
for(i = 0; i < 10; i++) {}
7+
8+
for(i = 0; i < 10; i++) {}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--unwindset main.0:10 --unwinding-assertions
4+
^Unwinding loop
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring

0 commit comments

Comments
 (0)