File tree 7 files changed +96
-4
lines changed
nondet_elements_longer_lists
nondet_elements_longer_lists_global 7 files changed +96
-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
+ typedef struct list
4
+ {
5
+ int datum ;
6
+ struct list * next ;
7
+ } list_nodet ;
8
+
9
+ void test_function (list_nodet * node )
10
+ {
11
+ int i = 0 ;
12
+ list_nodet * list_walker = node ;
13
+ while (list_walker )
14
+ {
15
+ list_walker -> datum = ++ i ;
16
+ list_walker = list_walker -> next ;
17
+ }
18
+ list_walker = node ;
19
+ i = 0 ;
20
+ while (list_walker )
21
+ {
22
+ assert (list_walker -> datum == ++ i );
23
+ list_walker = list_walker -> next ;
24
+ }
25
+ }
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
+ typedef struct list
4
+ {
5
+ int datum ;
6
+ struct list * next ;
7
+ } list_nodet ;
8
+
9
+ list_nodet * global_list ;
10
+ void test_function (void )
11
+ {
12
+ int i = 0 ;
13
+ list_nodet * list_walker = global_list ;
14
+ while (list_walker )
15
+ {
16
+ list_walker -> datum = ++ i ;
17
+ list_walker = list_walker -> next ;
18
+ }
19
+ list_walker = global_list ;
20
+ i = 0 ;
21
+ while (list_walker )
22
+ {
23
+ assert (list_walker -> datum == ++ i );
24
+ list_walker = list_walker -> next ;
25
+ }
26
+ }
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 @@ -182,16 +182,28 @@ void function_call_harness_generatort::implt::generate_nondet_globals(
182
182
{
183
183
if (nondet_globals)
184
184
{
185
+ // generating initialisation code may introduce new globals
186
+ // i.e. modify the symbol table.
187
+ // Modifying the symbol table while iterating over it is not
188
+ // a good idea, therefore we just collect the names of globals
189
+ // we need to initialise first and then generate the
190
+ // initialisation code for all of them.
191
+ auto globals = std::vector<symbol_exprt>{};
185
192
for (const auto &symbol_table_entry : *symbol_table)
186
193
{
187
194
const auto &symbol = symbol_table_entry.second ;
188
195
if (
189
196
symbol.is_static_lifetime && symbol.is_lvalue &&
197
+ symbol.type .id () != ID_code &&
190
198
!has_prefix (id2string (symbol.name ), CPROVER_PREFIX))
191
199
{
192
- generate_initialisation_code_for (function_body, symbol.symbol_expr ());
200
+ globals. push_back ( symbol.symbol_expr ());
193
201
}
194
202
}
203
+ for (auto const &global : globals)
204
+ {
205
+ generate_initialisation_code_for (function_body, global);
206
+ }
195
207
}
196
208
}
197
209
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