Skip to content

Commit ba0f8de

Browse files
committed
goto-instrument loop uwinding with strategies
1 parent 7f9a553 commit ba0f8de

File tree

49 files changed

+808
-182
lines changed

Some content is hidden

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

49 files changed

+808
-182
lines changed
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 10 --unwinding-assertions"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwind 10 --unwinding-assertions"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
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: 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwind 9"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^warning: ignoring

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
100
3+
"--unwind 100 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
100
3+
"--unwind 100 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwind 10 --partial-loops"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwind 100 --partial-loops"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^warning: ignoring

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
100
3+
"--unwind 100 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
"--unwind 5 --rest-loops"
4+
^Unwinding loop.*iteration 5
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
^Unwinding loop.*iteration 6

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
10
3+
"--unwind 10 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
100
3+
"--unwind 100 --partial-loops"
44
^SIGNAL=0$
55
^VERIFICATION SUCCESSFUL$
66
--

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@ goto_instrument=$src/goto-instrument/goto-instrument
66
cbmc=$src/cbmc/cbmc
77

88
function usage() {
9-
echo "Usage: chain unwind-num test_file.c"
9+
echo "Usage: chain <options> <testfile>"
1010
exit 1
1111
}
1212

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
13+
if [ $# -ne 2 ]; then
2214
usage
15+
exit 1
2316
fi
2417

18+
name=$(echo $2 | cut -d. -f1)
19+
2520
$goto_cc -o $name.gb $name.c
26-
$goto_instrument $name.gb ${name}-unwound.gb --unwind $unwind_num
21+
$goto_instrument $1 $name.gb ${name}-unwound.gb
22+
$goto_instrument --show-goto-functions ${name}-unwound.gb
2723
$cbmc ${name}-unwound.gb
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 --unwindset main.0:10 --unwinding-assertions"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
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+
6+
for(i = 0; i < 10; i++) {}
7+
8+
for(i = 0; i < 10; i++) {}
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+
"--unwindset main.0:10 --unwinding-assertions"
4+
^Unwinding loop
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
"--unwind 10 --unwindset main.0:-1"
4+
^Unwinding loop
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
void f()
3+
{
4+
int i;
5+
for (i = 0; i < 10; i++) {}
6+
}
7+
8+
void g()
9+
{
10+
int i;
11+
for (i = 0; i < 10; i++) {}
12+
for (i = 0; i < 10; i++) {}
13+
}
14+
15+
int main()
16+
{
17+
f();
18+
g();
19+
20+
int i;
21+
for(i = 0; i < 10; i++) {}
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwindset main.0:10,f.0:10,g.0:10,g.1:10 --unwinding-assertions"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--unwindset main.0:10,main.1:10,main.2:10 --unwinding-assertions"
4+
^SIGNAL=0$
5+
^VERIFICATION SUCCESSFUL$
6+
--
7+
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
int main()
3+
{
4+
int i;
5+
int j = 0;
6+
7+
for(i = 0; i < 10; i++) {
8+
j = 1;
9+
}
10+
11+
assert(j == 0);
12+
}

0 commit comments

Comments
 (0)