File tree 7 files changed +101
-4
lines changed
nondet_elements_longer_lists
nondet_elements_longer_lists_global 7 files changed +101
-4
lines changed Original file line number Diff line number Diff line change @@ -24,4 +24,4 @@ if [ -e "${name}-mod.gb" ] ; then
24
24
fi
25
25
26
26
$goto_harness " ${name} .gb" " ${name} -mod.gb" --harness-function-name $entry_point ${args}
27
- $cbmc --function $entry_point " ${name} -mod.gb"
27
+ $cbmc --function $entry_point " ${name} -mod.gb" --unwind 20 --unwinding-assertions
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ #define NULL 0
4
+
5
+ typedef struct list
6
+ {
7
+ int datum ;
8
+ struct list * next ;
9
+ } list_nodet ;
10
+
11
+ void test_function (list_nodet * node )
12
+ {
13
+ int i = 0 ;
14
+ list_nodet * list_walker = node ;
15
+ while (list_walker )
16
+ {
17
+ list_walker -> datum = ++ i ;
18
+ list_walker = list_walker -> next ;
19
+ }
20
+ list_walker = node ;
21
+ i = 0 ;
22
+ while (list_walker )
23
+ {
24
+ assert (list_walker -> datum == ++ i );
25
+ list_walker = list_walker -> next ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --harness-type call-function --max-nondet-tree-depth 4 --min-null-tree-depth 1 --function test_function
4
+ \[test_function.unwind.\d+\] line \d+ unwinding assertion loop 0: SUCCESS
5
+ \[test_function.unwind.\d+\] line \d+ unwinding assertion loop 1: SUCCESS
6
+ \[test_function.assertion.\d+\] line \d+ assertion list_walker->datum == \+\+i: SUCCESS
7
+ ^EXIT=0$
8
+ ^SIGNAL=0$
9
+ VERIFICATION SUCCESSFUL
10
+ --
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ #define NULL 0
4
+
5
+ typedef struct list
6
+ {
7
+ int datum ;
8
+ struct list * next ;
9
+ } list_nodet ;
10
+
11
+ list_nodet * global_list ;
12
+ void test_function (void )
13
+ {
14
+ int i = 0 ;
15
+ list_nodet * list_walker = global_list ;
16
+ while (list_walker )
17
+ {
18
+ list_walker -> datum = ++ i ;
19
+ list_walker = list_walker -> next ;
20
+ }
21
+ list_walker = global_list ;
22
+ i = 0 ;
23
+ while (list_walker )
24
+ {
25
+ assert (list_walker -> datum == ++ i );
26
+ list_walker = list_walker -> next ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --harness-type call-function --max-nondet-tree-depth 4 --min-null-tree-depth 1 --function test_function --nondet-globals
4
+ \[test_function.unwind.\d+\] line \d+ unwinding assertion loop 0: SUCCESS
5
+ \[test_function.unwind.\d+\] line \d+ unwinding assertion loop 1: SUCCESS
6
+ \[test_function.assertion.\d+\] line \d+ assertion list_walker->datum == \+\+i: SUCCESS
7
+ ^EXIT=0$
8
+ ^SIGNAL=0$
9
+ VERIFICATION SUCCESSFUL
10
+ --
Original file line number Diff line number Diff line change @@ -180,16 +180,29 @@ void function_call_harness_generatort::implt::generate_nondet_globals(
180
180
{
181
181
if (nondet_globals)
182
182
{
183
+ // generating initialisation code may introduce new globals
184
+ // i.e. modify the symbol table.
185
+ // Modifying the symbol table while iterating over it is not
186
+ // a good idea, therefore we just collect the names of globals
187
+ // we need to initialise first and then generate the
188
+ // initialisation code for all of them.
189
+ auto global_names = std::vector<irep_idt>{};
183
190
for (const auto &symbol_table_entry : *symbol_table)
184
191
{
185
192
const auto &symbol = symbol_table_entry.second ;
186
193
if (
187
194
symbol.is_static_lifetime && symbol.is_lvalue &&
195
+ symbol.type .id () != ID_code &&
188
196
!has_prefix (id2string (symbol.name ), CPROVER_PREFIX))
189
197
{
190
- generate_initialisation_code_for (function_body, symbol.symbol_expr () );
198
+ global_names. push_back ( symbol.name );
191
199
}
192
200
}
201
+ for (auto const &global_name : global_names)
202
+ {
203
+ generate_initialisation_code_for (
204
+ function_body, symbol_table->lookup_ref (global_name).symbol_expr ());
205
+ }
193
206
}
194
207
}
195
208
Original file line number Diff line number Diff line change @@ -93,8 +93,17 @@ void recursive_initializationt::initialize_pointer(
93
93
goto_model.symbol_table };
94
94
exprt choice =
95
95
allocate_objects.allocate_automatic_local_object (bool_typet{}, " choice" );
96
- auto pointee =
97
- allocate_objects.allocate_automatic_local_object (type.subtype (), " pointee" );
96
+ symbolt &pointee_symbol = get_fresh_aux_symbol (
97
+ type.subtype (),
98
+ " __goto_harness" ,
99
+ " pointee" ,
100
+ lhs.source_location (),
101
+ initialization_config.mode ,
102
+ goto_model.symbol_table );
103
+ pointee_symbol.is_static_lifetime = true ;
104
+ pointee_symbol.is_lvalue = true ;
105
+
106
+ auto pointee = pointee_symbol.symbol_expr ();
98
107
allocate_objects.declare_created_symbols (body);
99
108
body.add (code_assignt{lhs, null_pointer_exprt{type}});
100
109
bool is_unknown_struct_tag =
You can’t perform that action at this time.
0 commit comments