File tree Expand file tree Collapse file tree 12 files changed +187
-151
lines changed
Function_Pointer_Init_No_Candidate
goto-analyzer/value-set-function-pointers-simple Expand file tree Collapse file tree 12 files changed +187
-151
lines changed Original file line number Diff line number Diff line change 1
1
CORE
2
2
main.c
3
3
4
- ^EXIT=0$
5
- ^SIGNAL=0$
6
- \[f2.assertion.1\] line [0-9]+ assertion 0: SUCCESS
7
- \[main.assertion.1\] line [0-9]+ assertion x == 1: SUCCESS
4
+ ^\*\*\*\* WARNING: no body for function main::fptr_call
5
+ ^\*\*\*\* WARNING: no body for function main::fptr_call\$0
6
+ \[f2.assertion.1\] line [0-9]+ assertion 0: FAILURE
7
+ \[main.assertion.1\] line [0-9]+ assertion x == 1: FAILURE
8
8
\[main.assertion.2\] line [0-9]+ assertion x == 2: SUCCESS
9
- ^VERIFICATION SUCCESSFUL$
9
+ ^VERIFICATION FAILED$
10
+ ^EXIT=10$
11
+ ^SIGNAL=0$
10
12
--
11
13
^warning: ignoring
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ struct PtrWrapper
4
+ {
5
+ char * value_c ;
6
+ };
7
+
8
+ void fn (struct PtrWrapper wrapper )
9
+ {
10
+ assert (wrapper .value_c == 'B' );
11
+ }
12
+
13
+ void indirect (int (* fn_ptr )(char * ), char * data )
14
+ {
15
+ fn_ptr (data );
16
+ assert (0 );
17
+ }
18
+
19
+ int main ()
20
+ {
21
+ struct PtrWrapper wrapper ;
22
+ wrapper .value_c = 'A' ;
23
+
24
+ int (* alias )(char * ) = (int (* )(char * ))fn ;
25
+ indirect (alias , & wrapper .value_c );
26
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+
4
+ ^\*\*\*\* WARNING: no body for function indirect::fptr_call
5
+ ^\[indirect.assertion.1\] line 16 assertion 0: FAILURE$
6
+ ^VERIFICATION FAILED$
7
+ ^EXIT=10$
8
+ ^SIGNAL=0$
9
+ --
10
+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -4,9 +4,7 @@ typedef int (*other_function_type)(int n);
4
4
5
5
void foo (other_function_type other_function )
6
6
{
7
- // returning from the function call is unreachable -> the following assertion
8
- // should succeed
9
- // requesting `pointer-check` will then catch the fact that there is no valid
7
+ // requesting `pointer-check` will catch the fact that there is no valid
10
8
// candidate function to call resulting in an invalid function pointer
11
9
// failure
12
10
assert (other_function (4 ) > 5 );
Original file line number Diff line number Diff line change 1
1
CORE
2
2
main.c
3
3
--function foo --pointer-check
4
- ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) > 5: SUCCESS $
4
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) > 5: FAILURE $
5
5
^\[foo.pointer_dereference.\d+\] line \d+ no candidates for dereferenced function pointer: FAILURE$
6
6
^EXIT=10$
7
7
^SIGNAL=0$
Original file line number Diff line number Diff line change 10
10
^main::1::fun1 \(\) -> value-set-begin: ptr ->\(f\) :value-set-end
11
11
^main::1::fun2_show \(\) -> value-set-begin: ptr ->\(f\), ptr ->\(g\) :value-set-end
12
12
^main::1::fun3_show \(\) -> value-set-begin: ptr ->\(f\), ptr ->\(g\) :value-set-end
13
- ^fun_global_show \(\) -> value-set-begin: ptr ->\(f\), ptr ->\(g\) :value-set-end
13
+ ^fun_global_show \(\) -> value-set-begin: TOP :value-set-end
14
14
^EXIT=0$
15
15
^SIGNAL=0$
16
16
--
Original file line number Diff line number Diff line change 5
5
^SIGNAL=0$
6
6
^file test.c line 20 function main: replacing function pointer by 2 possible targets$
7
7
--
8
+ --
8
9
This test checks that the value-set-fi-based function pointer removal
9
10
precisely identifies the function to call for a particular function pointer
10
11
call.
Original file line number Diff line number Diff line change 5
5
^SIGNAL=0$
6
6
^file test.c line 19 function main: replacing function pointer by 0 possible targets$
7
7
--
8
+ --
8
9
This test checks that the value-set-fi-based function pointer removal
9
10
precisely identifies the function to call for a particular function pointer
10
11
call.
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ void value_set_fi_fp_removal(
31
31
message.status () << " Instrumenting" << messaget::eom;
32
32
33
33
// now replace aliases by addresses
34
+ std::list<irep_idt> fall_back_fns;
34
35
for (auto &f : goto_model.goto_functions .function_map )
35
36
{
36
37
for (auto target = f.second .body .instructions .begin ();
@@ -69,18 +70,26 @@ void value_set_fi_fp_removal(
69
70
70
71
if (functions.size () > 0 )
71
72
{
72
- remove_function_pointer (
73
+ fall_back_fns. push_back ( remove_function_pointer (
73
74
message_handler,
74
75
goto_model.symbol_table ,
75
76
f.second .body ,
76
77
f.first ,
77
78
target,
78
79
functions,
79
- true );
80
+ true )) ;
80
81
}
81
82
}
82
83
}
83
84
}
84
85
}
85
- goto_model.goto_functions .update ();
86
+
87
+ for (const auto &id : fall_back_fns)
88
+ {
89
+ goto_model.goto_functions .function_map [id].set_parameter_identifiers (
90
+ to_code_type (ns.lookup (id).type ));
91
+ }
92
+
93
+ if (!fall_back_fns.empty ())
94
+ goto_model.goto_functions .update ();
86
95
}
You can’t perform that action at this time.
0 commit comments