Skip to content

Commit c655301

Browse files
author
Daniel Kroening
authored
Merge pull request #262 from danpoe/goto-function-inlining
Goto function inlining
2 parents 268f751 + 05f19bf commit c655301

File tree

35 files changed

+2372
-754
lines changed

35 files changed

+2372
-754
lines changed

regression/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
DIRS = ansi-c cbmc cpp goto-instrument goto-instrument-unwind goto-analyzer
1+
2+
DIRS = ansi-c cbmc cpp goto-instrument goto-instrument-unwind goto-analyzer inlining
23

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

regression/inlining/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
default: tests.log
2+
3+
test:
4+
@./test.sh
5+
6+
tests.log: ../test.pl
7+
@./test.sh
8+
9+
show:
10+
@for dir in *; do \
11+
if [ -d "$$dir" ]; then \
12+
vim -o "$$dir/*.java" "$$dir/*.out"; \
13+
fi; \
14+
done;
15+
16+
clean:
17+
find . -name '*.*~' | xargs rm -f
18+
find . -name '*.out' | xargs rm -f
19+
find . -name '*.o' | xargs rm -f
20+
rm -f tests.log

regression/inlining/chain.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
src=../../../src
6+
goto_cc=$src/goto-cc/goto-cc
7+
goto_instrument=$src/goto-instrument/goto-instrument
8+
cbmc=$src/cbmc/cbmc
9+
10+
name=${@:$#}
11+
name=${name%.c}
12+
13+
args=${@:1:$#-1}
14+
15+
$goto_cc -o $name.o $name.c
16+
$goto_instrument $args $name.o $name-new.o
17+
$goto_instrument --show-goto-functions $name-new.o
18+
$cbmc $name-new.o
19+

regression/inlining/inline_01/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
int h() {
6+
return 9;
7+
}
8+
9+
void g(int i) {
10+
x += i + h(); // += 12
11+
}
12+
13+
void f(int i, int j) {
14+
g(i);
15+
x += i + j; // +=10
16+
}
17+
18+
int main()
19+
{
20+
x = 0;
21+
f(3, 7);
22+
assert(x == 22);
23+
}
24+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
f[(].*[)];$
9+
g[(].*[)];$
10+
h[(].*[)];$
11+
^warning: ignoring

regression/inlining/inline_02/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
int h() {
6+
return 9;
7+
}
8+
9+
void g(int i) {
10+
x += i + h(); // += 12
11+
}
12+
13+
void f(int i, int j) {
14+
g(i);
15+
x += i + j; // +=10
16+
}
17+
18+
int main()
19+
{
20+
x = 0;
21+
f(3, 7);
22+
assert(x == 22);
23+
}
24+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--partial-inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
f[(].*[)];$
8+
g[(].*[)];$
9+
h[(].*[)];$
10+
--
11+
^warning: ignoring

regression/inlining/inline_03/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
inline int h() {
6+
return 9;
7+
}
8+
9+
void g(int i) {
10+
x += i + h(); // += 12
11+
}
12+
13+
void f(int i, int j) {
14+
g(i);
15+
x += i + j; // +=10
16+
}
17+
18+
int main()
19+
{
20+
x = 0;
21+
f(3, 7);
22+
assert(x == 22);
23+
}
24+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--partial-inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
f[(].*[)];$
8+
g[(].*[)];$
9+
--
10+
h[(].*[)];$
11+
^warning: ignoring

regression/inlining/inline_04/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
int h() {
6+
return 9;
7+
}
8+
9+
void g(int i) {
10+
x += i + h(); // += 12
11+
}
12+
13+
void f(int i, int j) {
14+
g(i);
15+
x += i + j; // +=10
16+
}
17+
18+
void other_func() {}
19+
20+
int main()
21+
{
22+
x = 0;
23+
f(3, 7);
24+
other_func();
25+
26+
assert(x == 22);
27+
}
28+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--function-inline main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
g[(].*[)];$
8+
h[(].*[)];$
9+
--
10+
f[(].*[)];$
11+
other_func[(].*[)];$
12+
^warning: ignoring

regression/inlining/inline_05/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
void f()
6+
{
7+
x += 1;
8+
9+
if(x < 10)
10+
f();
11+
}
12+
13+
void h()
14+
{
15+
x += 1;
16+
if(x < 20)
17+
g();
18+
}
19+
20+
void g()
21+
{
22+
x += 1;
23+
h();
24+
}
25+
26+
int main()
27+
{
28+
// direct recursion
29+
x = 0;
30+
f();
31+
assert(x == 1);
32+
33+
// indirect recursion
34+
x = 0;
35+
g();
36+
assert(x == 2);
37+
}
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
recursion.*ignored.*[`]f
8+
recursion.*ignored.*[`]g
9+
--
10+
^warning: ignoring

regression/inlining/inline_06/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
inline void f()
6+
{
7+
x += 1;
8+
9+
if(x < 10)
10+
f();
11+
}
12+
13+
inline void h()
14+
{
15+
x += 1;
16+
if(x < 20)
17+
g();
18+
}
19+
20+
inline void g()
21+
{
22+
x += 1;
23+
h();
24+
}
25+
26+
int main()
27+
{
28+
// direct recursion
29+
x = 0;
30+
f();
31+
assert(x == 10);
32+
33+
// indirect recursion
34+
x = 0;
35+
g();
36+
assert(x == 20);
37+
}
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--partial-inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
recursion.*ignored.*[`]f
8+
recursion.*ignored.*[`]g
9+
--
10+
^warning: ignoring

regression/inlining/inline_07/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
void f()
6+
{
7+
x += 1;
8+
9+
if(x < 10)
10+
f();
11+
}
12+
13+
void h()
14+
{
15+
x += 1;
16+
if(x < 20)
17+
g();
18+
}
19+
20+
void g()
21+
{
22+
x += 1;
23+
h();
24+
}
25+
26+
int main()
27+
{
28+
// direct recursion
29+
x = 0;
30+
f();
31+
assert(x == 1);
32+
33+
// indirect recursion
34+
x = 0;
35+
g();
36+
assert(x == 2);
37+
}
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function-inline main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
recursion.*ignored.*[`]f
8+
recursion.*ignored.*[`]g
9+
--
10+
^warning: ignoring

regression/inlining/inline_08/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
int x;
4+
5+
int f()
6+
{
7+
if(x)
8+
return 1;
9+
else
10+
return 2;
11+
12+
return 3;
13+
}
14+
15+
int main()
16+
{
17+
int y;
18+
y = f();
19+
}
20+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--inline
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
y = 1;
8+
y = 2;
9+
y = 3;
10+
--
11+
^warning: ignoring

0 commit comments

Comments
 (0)