File tree Expand file tree Collapse file tree 3 files changed +44
-13
lines changed
regression/contracts/contracts_with_function_pointers
src/goto-instrument/contracts Expand file tree Collapse file tree 3 files changed +44
-13
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stddef.h>
3
+
4
+ int x = 0 ;
5
+
6
+ void foo (int * y )
7
+ {
8
+ * y = 1 ;
9
+ }
10
+
11
+ int * baz ()
12
+ {
13
+ return & x ;
14
+ }
15
+
16
+ void bar (void (* fun_ptr )(), int * x ) __CPROVER_requires (fun_ptr != NULL )
17
+ __CPROVER_requires (x != NULL ) __CPROVER_assigns (* x ) __CPROVER_ensures (* x == 1 )
18
+ {
19
+ * (baz ()) = 1 ;
20
+ fun_ptr (x );
21
+ }
22
+
23
+ int main ()
24
+ {
25
+ assert (x == 0 );
26
+ void (* fun_ptr )() = foo ;
27
+ bar (fun_ptr , & x );
28
+ assert (x == 1 );
29
+ return 0 ;
30
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-contract bar
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS$
7
+ ^\[bar.\d+\] line \d+ Check that \*return\_value\_baz is assignable: SUCCESS$
8
+ ^\[foo.\d+\] line \d+ Check that \*y is assignable: SUCCESS$
9
+ ^VERIFICATION SUCCESSFUL$
10
+ --
11
+ Checks whether CBMC properly instrument functions with function pointers
12
+ during contract enforcement.
Original file line number Diff line number Diff line change @@ -673,19 +673,8 @@ void code_contractst::instrument_call_statement(
673
673
" The first argument of instrument_call_statement should always be "
674
674
" a function call" );
675
675
676
- irep_idt called_function;
677
- if (instruction_it->call_function ().id () == ID_dereference)
678
- {
679
- called_function =
680
- to_symbol_expr (
681
- to_dereference_expr (instruction_it->call_function ()).pointer ())
682
- .get_identifier ();
683
- }
684
- else
685
- {
686
- called_function =
687
- to_symbol_expr (instruction_it->call_function ()).get_identifier ();
688
- }
676
+ irep_idt called_function =
677
+ to_symbol_expr (instruction_it->call_function ()).get_identifier ();
689
678
690
679
if (called_function == " malloc" )
691
680
{
You can’t perform that action at this time.
0 commit comments