File tree 7 files changed +102
-0
lines changed
Function_Pointer_Init_No_Candidate
Function_Pointer_Init_One_Candidate
Function_Pointer_Init_Two_Candidates 7 files changed +102
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ typedef int (* other_function_type )(int n );
4
+
5
+ void foo (other_function_type other_function )
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
10
+ // candidate function to call resulting in an invalid function pointer
11
+ // failure
12
+ assert (other_function (4 ) > 5 );
13
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --function foo --pointer-check
4
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) > 5: SUCCESS$
5
+ ^\[foo.pointer_dereference.\d+\] line \d+ invalid function pointer: FAILURE$
6
+ ^EXIT=10$
7
+ ^SIGNAL=0$
8
+ ^VERIFICATION FAILED
9
+ --
10
+ ^warning: ignoring
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ int identity (int n )
4
+ {
5
+ return n ;
6
+ }
7
+
8
+ typedef int (* other_function_type )(int n );
9
+
10
+ void foo (other_function_type other_function )
11
+ {
12
+ // the following assertion is reachable and should fail (the only candidate is identity)
13
+ assert (other_function (4 ) == 5 );
14
+ // the following assertion should succeed
15
+ assert (other_function (4 ) == 4 );
16
+ }
17
+
18
+ int main ()
19
+ {
20
+ foo (& identity );
21
+ return 0 ;
22
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --function foo
4
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) == 5: FAILURE$
5
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) == 4: SUCCESS$
6
+ ^EXIT=10$
7
+ ^SIGNAL=0$
8
+ ^VERIFICATION FAILED
9
+ --
10
+ ^warning: ignoring
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ int identity (int n )
4
+ {
5
+ return n ;
6
+ }
7
+ int increment (int n )
8
+ {
9
+ return n + 1 ;
10
+ }
11
+
12
+ typedef int (* other_function_type )(int n );
13
+
14
+ void foo (other_function_type other_function )
15
+ {
16
+ // the following assertion is reachable and should fail (because of the identity case)
17
+ assert (other_function (4 ) == 5 );
18
+ // the following assertion should succeed (satisfied by both candidates)
19
+ assert (other_function (4 ) >= 4 );
20
+ }
21
+
22
+ int main ()
23
+ {
24
+ foo (& identity );
25
+ foo (& increment );
26
+ return 0 ;
27
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --function foo
4
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) == 5: FAILURE$
5
+ ^\[foo.assertion.\d+\] line \d+ assertion other_function\(4\) >= 4: SUCCESS$
6
+ ^EXIT=10$
7
+ ^SIGNAL=0$
8
+ ^VERIFICATION FAILED
9
+ --
10
+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -54,6 +54,16 @@ void symbol_factoryt::gen_nondet_init(
54
54
const pointer_typet &pointer_type=to_pointer_type (type);
55
55
const typet &subtype = pointer_type.subtype ();
56
56
57
+ if (subtype.id () == ID_code)
58
+ {
59
+ // Handle the pointer-to-code case separately:
60
+ // leave as nondet_ptr to allow `remove_function_pointers`
61
+ // to replace the pointer.
62
+ assignments.add (
63
+ code_assignt{expr, side_effect_expr_nondett{pointer_type, loc}});
64
+ return ;
65
+ }
66
+
57
67
if (subtype.id () == ID_struct_tag)
58
68
{
59
69
const irep_idt struct_tag = to_struct_tag_type (subtype).get_identifier ();
You can’t perform that action at this time.
0 commit comments