Skip to content

Commit cae911c

Browse files
author
thk123
committed
Added flag for goto-instrument to just remove const function pointers
Added a flag --remove-const-function-pointers for goto-instrument that can be used instead of --remove-function-pointers to only remove function pointers where we can resolve to something more precise that all functions with a matching signature.
1 parent 30804d3 commit cae911c

File tree

17 files changed

+361
-15
lines changed

17 files changed

+361
-15
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
const void_fp fp_tbl[] = {f2, f3 ,f4};
16+
17+
// There is a basic check that excludes all functions that aren't used anywhere
18+
// This ensures that check can't work in this example
19+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
20+
21+
void func(int i)
22+
{
23+
fp_tbl[i]();
24+
}
25+
26+
int main()
27+
{
28+
for(int i=0;i<3;i++)
29+
{
30+
func(i);
31+
}
32+
33+
return 0;
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--verbosity 10 --pointer-check --remove-const-function-pointers
4+
5+
^\s*IF fp_tbl\[(signed long int)i\] == f2 THEN GOTO [0-9]$
6+
^\s*IF fp_tbl\[(signed long int)i\] == f3 THEN GOTO [0-9]$
7+
^\s*IF fp_tbl\[(signed long int)i\] == f4 THEN GOTO [0-9]$
8+
^SIGNAL=0$
9+
--
10+
^\s*IF fp_tbl\[(signed long int)i\] == f1 THEN GOTO [0-9]$
11+
^\s*IF fp_tbl\[(signed long int)i\] == f5 THEN GOTO [0-9]$
12+
^\s*IF fp_tbl\[(signed long int)i\] == f6 THEN GOTO [0-9]$
13+
^\s*IF fp_tbl\[(signed long int)i\] == f7 THEN GOTO [0-9]$
14+
^\s*IF fp_tbl\[(signed long int)i\] == f8 THEN GOTO [0-9]$
15+
^\s*IF fp_tbl\[(signed long int)i\] == f9 THEN GOTO [0-9]$
16+
^warning: ignoring
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
const void_fp fp_tbl[] = {f2, f3 ,f4};
16+
17+
// There is a basic check that excludes all functions that aren't used anywhere
18+
// This ensures that check can't work in this example
19+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
20+
21+
void func(int i)
22+
{
23+
fp_tbl[i]();
24+
}
25+
26+
int main()
27+
{
28+
for(int i=0;i<3;i++)
29+
{
30+
func(i);
31+
}
32+
33+
return 0;
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--verbosity 10 --pointer-check --remove-function-pointers
4+
5+
^\s*IF fp_tbl\[(signed long int)i\] == f2 THEN GOTO [0-9]$
6+
^\s*IF fp_tbl\[(signed long int)i\] == f3 THEN GOTO [0-9]$
7+
^\s*IF fp_tbl\[(signed long int)i\] == f4 THEN GOTO [0-9]$
8+
^SIGNAL=0$
9+
--
10+
^\s*IF fp_tbl\[(signed long int)i\] == f1 THEN GOTO [0-9]$
11+
^\s*IF fp_tbl\[(signed long int)i\] == f5 THEN GOTO [0-9]$
12+
^\s*IF fp_tbl\[(signed long int)i\] == f6 THEN GOTO [0-9]$
13+
^\s*IF fp_tbl\[(signed long int)i\] == f7 THEN GOTO [0-9]$
14+
^\s*IF fp_tbl\[(signed long int)i\] == f8 THEN GOTO [0-9]$
15+
^\s*IF fp_tbl\[(signed long int)i\] == f9 THEN GOTO [0-9]$
16+
^warning: ignoring
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--verbosity 10 --pointer-check --remove-const-function-pointers
4+
5+
^\s*fp();$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--verbosity 10 --pointer-check --remove-function-pointers
4+
5+
^\s*IF fp == f1 THEN GOTO [0-9]$
6+
^\s*IF fp == f2 THEN GOTO [0-9]$
7+
^\s*IF fp == f3 THEN GOTO [0-9]$
8+
^\s*IF fp == f4 THEN GOTO [0-9]$
9+
^\s*IF fp == f5 THEN GOTO [0-9]$
10+
^\s*IF fp == f6 THEN GOTO [0-9]$
11+
^\s*IF fp == f7 THEN GOTO [0-9]$
12+
^\s*IF fp == f8 THEN GOTO [0-9]$
13+
^\s*IF fp == f9 THEN GOTO [0-9]$
14+
^SIGNAL=0$
15+
--
16+
^warning: ignoring
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
fp();
23+
}
24+
25+
int main()
26+
{
27+
func();
28+
29+
return 0;
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--verbosity 10 --pointer-check --remove-const-function-pointers
4+
5+
^\s*f2();
6+
--
7+
^warning: ignoring

0 commit comments

Comments
 (0)