Skip to content

Commit d825d04

Browse files
committed
Use remove-function-pointers code for restricted function pointers
We had two instances of code generating an if-else sequence of function calls for function pointers. The code used with --restrict-function-pointer, however, was not able to cope with type mismatches. Make the code from remove_function_pointers re-usable in both contexts, enabling support for additional type casts. Fixes: #6368
1 parent d460e1c commit d825d04

File tree

27 files changed

+202
-157
lines changed

27 files changed

+202
-157
lines changed

regression/cbmc/Function_Pointer_Init_No_Candidate/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--function foo --pointer-check
44
^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) > 5: SUCCESS$
5-
^\[foo.pointer_dereference.\d+\] line \d+ invalid function pointer: FAILURE$
5+
^\[foo.pointer_dereference.\d+\] line \d+ no candidates for dereferenced function pointer: FAILURE$
66
^EXIT=10$
77
^SIGNAL=0$
88
^VERIFICATION FAILED

regression/goto-analyzer/approx-const-fp-array-variable-struct-const-fp-with-zero/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ main.c
55
^\s*IF .*::fp = address_of\(f2\) THEN GOTO [0-9]$
66
^\s*IF .*::fp = address_of\(f3\) THEN GOTO [0-9]$
77
^\s*IF .*::fp = address_of\(f4\) THEN GOTO [0-9]$
8-
^\s*ASSERT false // invalid function pointer$
8+
^\s*ASSERT false // dereferenced function pointer must be one of \[f[2-4], f[2-4], f[2-4]\]$
99
^EXIT=0$
1010
^SIGNAL=0$
1111
--

regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // no candidates for dereferenced function pointer
66
^EXIT=0$
77
^SIGNAL=0$
88
function func: replacing function pointer by 0 possible targets

regression/goto-analyzer/no-match-const-fp-const-fp-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // no candidates for dereferenced function pointer
66
^EXIT=0$
77
^SIGNAL=0$
88
replacing function pointer by 0 possible targets

regression/goto-analyzer/no-match-const-fp-const-pointer-const-struct-const-fp-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // dereferenced function pointer must be one of \[(f[1-9], ){8}f[1-9]\]$
66
replacing function pointer by 9 possible targets
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-analyzer/no-match-const-fp-dereference-const-pointer-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // dereferenced function pointer must be one of \[(f[1-9], ){8}f[1-9]\]$
66
replacing function pointer by 9 possible targets
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-analyzer/no-match-const-fp-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // no candidates for dereferenced function pointer
66
function func: replacing function pointer by 0 possible targets
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-analyzer/no-match-const-struct-non-const-fp-null/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CORE
22
main.c
33
--show-goto-functions --pointer-check
44
^Removal of function pointers and virtual functions$
5-
^\s*ASSERT false // invalid function pointer$
5+
^\s*ASSERT false // no candidates for dereferenced function pointer
66
^EXIT=0$
77
^SIGNAL=0$
88
replacing function pointer by 0 possible targets

regression/goto-instrument/restrict-function-pointer-by-name-global/test.desc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
CORE
22
test.c
33
--restrict-function-pointer-by-name fp/f,g
4-
\[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be one of \[(f, g)|(g, f)\]: SUCCESS
4+
\[main\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be one of \[(f, g)|(g, f)\]: SUCCESS
5+
\[main.assertion.1\] line \d+ assertion: FAILURE
56
\[main.assertion.2\] line \d+ assertion: FAILURE
6-
\[main.assertion.3\] line \d+ assertion: FAILURE
7-
\[main.assertion.4\] line \d+ assertion: SUCCESS
7+
\[main.assertion.3\] line \d+ assertion: SUCCESS
88
f\(\)
99
g\(\)
1010
^EXIT=10$

regression/goto-instrument/restrict-function-pointer-by-name-local/test.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
test.c
33
--restrict-function-pointer-by-name main::1::fp/f
4-
\[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be f: SUCCESS
5-
\[main\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS
4+
\[main\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be f: SUCCESS
5+
\[main\.assertion\.1\] line \d+ assertion fp\(\) == 1: SUCCESS
66
f\(\)
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-instrument/restrict-function-pointer-by-name-parameter/test.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
test.c
33
--restrict-function-pointer-by-name use_fp::fp/f
4-
\[use_fp\.assertion\.1\] line \d+ dereferenced function pointer at use_fp\.function_pointer_call\.1 must be f: SUCCESS
5-
\[use_fp\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS
4+
\[use_fp\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be f: SUCCESS
5+
\[use_fp\.assertion\.1\] line \d+ assertion fp\(\) == 1: SUCCESS
66
f\(\)
77
^EXIT=0$
88
^SIGNAL=0$

regression/goto-instrument/restrict-function-pointer-goto-target/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ test.c
33
--restrict-function-pointer main.function_pointer_call.1/f
44
^EXIT=0$
55
^SIGNAL=0$
6-
\[main.assertion.1\] line \d+ dereferenced function pointer at main.function_pointer_call.1 must be f: SUCCESS
6+
\[main.pointer_dereference.1\] line \d+ dereferenced function pointer must be f: SUCCESS
77
--
88
--
99
This test checks that a function pointer call that is the target of a goto (in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
3+
typedef int (*fptr_t)(long long);
4+
5+
void use_f(fptr_t fptr)
6+
{
7+
assert(fptr(10) == 11);
8+
}
9+
10+
int f(int x)
11+
{
12+
return x + 1;
13+
}
14+
15+
int g(int x)
16+
{
17+
return x;
18+
}
19+
20+
int main(void)
21+
{
22+
int one = 1;
23+
24+
// We take the address of f and g. In this case remove_function_pointers()
25+
// would create a case distinction involving both f and g in the function
26+
// use_f() above.
27+
use_f(one ? f : g);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--restrict-function-pointer use_f.function_pointer_call.1/f
4+
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) == 11: SUCCESS
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This test checks that the function f is permitted for the first function pointer
10+
call in function use_f, despite parameters having different integer types.

regression/goto-instrument/restrict-function-pointer-to-complex-expression/test.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
test.c
33
--restrict-function-pointer 'use_fg.function_pointer_call.1/f,g'
4-
\[use_fg.assertion.2\] line \d+ assertion \(choice \? fptr : gptr\)\(10\) == 10 \+ choice: SUCCESS
5-
\[use_fg.assertion.1\] line \d+ dereferenced function pointer at use_fg.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: SUCCESS
4+
\[use_fg.assertion.1\] line \d+ assertion \(choice \? fptr : gptr\)\(10\) == 10 \+ choice: SUCCESS
5+
\[use_fg.pointer_dereference.1\] line \d+ dereferenced function pointer must be one of \[(f|g), (f|g)\]: SUCCESS
66
^EXIT=0$
77
^SIGNAL=0$
88
--

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-incorrectly/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--restrict-function-pointer use_f.function_pointer_call.1/f,g
4-
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
4+
\[use_f\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
77
--

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file-and-command-line-options/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--function-pointer-restrictions-file restrictions.json --restrict-function-pointer use_f.function_pointer_call.1/g --restrict-function-pointer-by-name use_f::fptr/h
4-
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g|h), (f|g|h), (f|g|h)\]: FAILURE
4+
\[use_f\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be one of \[(f|g|h), (f|g|h), (f|g|h)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
77
--

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--function-pointer-restrictions-file restrictions.json
4-
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
4+
\[use_f\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
77
--

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-multiple-files/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--function-pointer-restrictions-file restrictions_1.json --function-pointer-restrictions-file restrictions_2.json
4-
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
4+
\[use_f\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
77
--
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
test.c
33
--restrict-function-pointer use_f.function_pointer_call.1/f,g
4-
\[use_f\.assertion\.2\] line \d+ assertion fptr\(10\) >= 10: SUCCESS
4+
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) >= 10: SUCCESS
55
^EXIT=0$
66
^SIGNAL=0$

regression/goto-instrument/restrict-function-pointer-to-single-function-incorrectly/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--restrict-function-pointer use_f.function_pointer_call.1/f
4-
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be f: FAILURE
4+
\[use_f\.pointer_dereference\.1\] line \d+ dereferenced function pointer must be f: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
77
--

regression/goto-instrument/restrict-function-pointer-to-single-function/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--restrict-function-pointer use_f.function_pointer_call.1/f
4-
\[use_f\.assertion\.2\] line \d+ assertion fptr\(10\) == 11: SUCCESS
4+
\[use_f\.assertion\.1\] line \d+ assertion fptr\(10\) == 11: SUCCESS
55
^EXIT=0$
66
^SIGNAL=0$
77
--

src/goto-instrument/goto_instrument_parse_options.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10341034
function_pointer_restrictionst::from_options(
10351035
options, goto_model, log.get_message_handler());
10361036

1037-
restrict_function_pointers(goto_model, function_pointer_restrictions);
1037+
restrict_function_pointers(
1038+
ui_message_handler, goto_model, function_pointer_restrictions);
10381039
}
10391040
}
10401041

0 commit comments

Comments
 (0)