Skip to content

Commit 0740ac2

Browse files
authored
Merge pull request #5436 from polgreen/value_set_fi_fp_removal
goto-instrument: function pointer removal with value_set_fi
2 parents 1426dc0 + 2960187 commit 0740ac2

File tree

17 files changed

+497
-0
lines changed

17 files changed

+497
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f()
6+
{
7+
}
8+
9+
void g()
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
fp_t fp = f;
16+
fp();
17+
18+
// this would fool an analysis that looks for functions whose address is taken
19+
fp_t other_fp = g;
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: f$
7+
--
8+
^ function: g$
9+
--
10+
This test checks that the value-set-fi-based function pointer removal
11+
precisely identifies the function to call for a particular function pointer
12+
call.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
typedef void (*fp_t)(int, int);
3+
4+
void add(int a, int b)
5+
{
6+
}
7+
void subtract(int a, int b)
8+
{
9+
}
10+
void multiply(int a, int b)
11+
{
12+
}
13+
14+
int main()
15+
{
16+
// fun_ptr_arr is an array of function pointers
17+
void (*fun_ptr_arr[])(int, int) = {add, subtract, add};
18+
19+
// Multiply should not be added into the value set
20+
fp_t other_fp = multiply;
21+
void (*fun_ptr_arr2[])(int, int) = {multiply, subtract, add};
22+
23+
// the fp removal over-approximates and assumes this could be any pointer in the array
24+
(*fun_ptr_arr[0])(1, 1);
25+
26+
return 0;
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: add$
7+
^ function: subtract$
8+
--
9+
^ function: multiply$
10+
--
11+
This test checks that the value-set-fi-based function pointer removal
12+
precisely identifies the function to call for a particular function pointer
13+
call.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
typedef void (*fp_t)(int, int);
2+
3+
void add(int a, int b)
4+
{
5+
}
6+
void subtract(int a, int b)
7+
{
8+
}
9+
void multiply(int a, int b)
10+
{
11+
}
12+
13+
int main()
14+
{
15+
// fun_ptr_arr is an array of function pointers
16+
struct my_struct
17+
{
18+
fp_t first_pointer;
19+
fp_t second_pointer;
20+
} struct1;
21+
22+
struct1.first_pointer = add;
23+
24+
// Multiply and subtract should not be added into the value set
25+
fp_t other_fp = multiply;
26+
struct1.second_pointer = subtract;
27+
28+
// this pointer can only be "add"
29+
struct1.first_pointer(1, 1);
30+
31+
return 0;
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ function: add$
7+
--
8+
^ function: multiply$
9+
^ function: subtract$
10+
--
11+
This test checks that the value-set-fi-based function pointer removal
12+
precisely identifies the function to call for a particular function pointer
13+
call.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f()
6+
{
7+
}
8+
9+
void g()
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
// the value set for fp is empty, defaults to standard function pointer removal behaviour
16+
fp_t other_fp = g;
17+
other_fp = f;
18+
19+
fp_t fp;
20+
fp();
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^file test.c line 20 function main: replacing function pointer by 2 possible targets$
7+
--
8+
This test checks that the value-set-fi-based function pointer removal
9+
precisely identifies the function to call for a particular function pointer
10+
call.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
typedef void (*fp_t)();
4+
5+
void f(int x)
6+
{
7+
}
8+
9+
void g(int y)
10+
{
11+
}
12+
13+
int main(void)
14+
{
15+
// the value set is empty, defaults to standard function pointer removal behaviour
16+
fp_t other_fp = g;
17+
18+
fp_t fp;
19+
fp();
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--value-set-fi-fp-removal
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^file test.c line 19 function main: replacing function pointer by 0 possible targets$
7+
--
8+
This test checks that the value-set-fi-based function pointer removal
9+
precisely identifies the function to call for a particular function pointer
10+
call.

0 commit comments

Comments
 (0)