Skip to content

Commit 79a8b9f

Browse files
author
thk123
committed
Adding tests for simplify function pointer removal
The variable sensitivity domain should be able to simplify the if statements produced by the function pointer removal, even in the cases where the pointer isn't definitely const.
1 parent 92a84dc commit 79a8b9f

File tree

16 files changed

+375
-0
lines changed

16 files changed

+375
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp = f2;
22+
23+
// Warning: this loses const-ness of f2
24+
void_fp * p2fp = (void_fp*)&fp;
25+
*p2fp = &f4;
26+
27+
fp();
28+
}
29+
30+
int main()
31+
{
32+
func();
33+
34+
return 0;
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 9
5+
^Unmodified: .* goto: 9
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
void f1 (void) { printf("%i\n", 1); }
5+
void f2 (void) { printf("%i\n", 2); }
6+
void f3 (void) { printf("%i\n", 3); }
7+
void f4 (void) { printf("%i\n", 4); }
8+
void f5 (void) { printf("%i\n", 5); }
9+
void f6 (void) { printf("%i\n", 6); }
10+
void f7 (void) { printf("%i\n", 7); }
11+
void f8 (void) { printf("%i\n", 8); }
12+
void f9 (void) { printf("%i\n", 9); }
13+
14+
typedef void(*void_fp)(void);
15+
16+
// There is a basic check that excludes all functions that aren't used anywhere
17+
// This ensures that check can't work in this example
18+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
19+
20+
void func()
21+
{
22+
void_fp * const fp_tbl= malloc(sizeof(void_fp) * 3);
23+
fp_tbl[0]=f2;
24+
fp_tbl[1]=f3;
25+
fp_tbl[2]=f4;
26+
27+
const void_fp fp = fp_tbl[1];
28+
fp();
29+
}
30+
31+
int main()
32+
{
33+
func();
34+
35+
return 0;
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 8
5+
^Unmodified: .* goto: 10
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step. This requires supporting tracking arrays assigned dynamically
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func(void_fp fp)
20+
{
21+
fp();
22+
}
23+
24+
int main(int argc, char** argv)
25+
{
26+
27+
func(&f2);
28+
return 0;
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 7
5+
^Unmodified: .* goto: 11
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp start_fp = f2;
22+
const void_fp * const fp_tbl[] = { &start_fp, &start_fp, &start_fp };
23+
24+
// warning: loses const
25+
void_fp * arr_ptr=fp_tbl[0];
26+
(*arr_ptr) = f5;
27+
arr_ptr++;
28+
(*arr_ptr) = f5;
29+
30+
const void_fp * const fp = fp_tbl[1];
31+
32+
33+
(*fp)();
34+
}
35+
36+
int main()
37+
{
38+
func();
39+
40+
return 0;
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 8
5+
^Unmodified: .* goto: 10
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp_tbl[] = {f2, f3 ,f4};
22+
23+
// warning: loses const
24+
void_fp * arr_ptr=&fp_tbl[0];
25+
(*arr_ptr) = f5;
26+
arr_ptr++;
27+
(*arr_ptr) = f5;
28+
29+
const void_fp fp = &fp_tbl[1];
30+
31+
fp();
32+
}
33+
34+
int main()
35+
{
36+
func();
37+
38+
return 0;
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 8
5+
^Unmodified: .* goto: 10
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
void_fp fp = f2;
22+
fp = f3;
23+
fp();
24+
}
25+
26+
int main()
27+
{
28+
func();
29+
30+
return 0;
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 8
5+
^Unmodified: .* goto: 10
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
const void_fp fp = f3;
22+
const void_fp fp2 = f4;
23+
const void_fp* p2fp = &fp;
24+
25+
// legal:
26+
p2fp = &fp2;
27+
const void_fp final_fp=*p2fp;
28+
final_fp();
29+
}
30+
31+
int main()
32+
{
33+
func();
34+
35+
return 0;
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 9
5+
^Unmodified: .* goto: 9
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func(int i, int j)
20+
{
21+
const void_fp fp_tbl[] = {fp_all[i*2], fp_all[j+1]};
22+
const void_fp fp = fp_tbl[1];
23+
fp();
24+
}
25+
26+
int main(int argc, char** argv)
27+
{
28+
29+
func(argc,0);
30+
return 0;
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--simplify out_simplified.gb --variable --arrays --structs --pointers
4+
^Simplified: .* goto: 3
5+
^Unmodified: .* goto: 15
6+
^SIGNAL=0$
7+
^EXIT=0$
8+
--
9+
^warning: ignoring
10+
--
11+
Check the GOTOs generated by the function pointer removal are removed by the
12+
simplify step. The number fo removed goto statements doesn't seem correct,
13+
but inspecting the output using show-goto-functions reveals the right program.

0 commit comments

Comments
 (0)