Skip to content

Commit 9ca0824

Browse files
committed
Rewrite the recursive constructors
Previously all recursive initialisation took place in a single function. Now each type has it's own constructor function, which are called recursively. The results (variables to be initialised) are passed by pointer.
1 parent d0212b9 commit 9ca0824

File tree

6 files changed

+502
-329
lines changed

6 files changed

+502
-329
lines changed

regression/goto-harness/pointer-to-array-function-parameters-multi-arg-wrong/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ test.c
33
--harness-type call-function --function is_prefix_of --treat-pointer-as-array string --treat-pointer-as-array prefix --associated-array-size string:string_size --associated-array-size prefix:prefix_size --max-array-size 5
44
^EXIT=10$
55
^SIGNAL=0$
6-
\[is_prefix_of.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside object bounds in prefix\[\(signed( long)* int\)ix\]: FAILURE
6+
\[is_prefix_of.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in prefix\[\(signed( long)* int\)ix\]: FAILURE
77
VERIFICATION FAILED
88
--
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
test.c
33
--harness-type call-function --function test --treat-pointer-as-array arr
4-
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed( long)* int\)0\]: SUCCESS
5-
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed( long)* int\)10\]: FAILURE
4+
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed( long)* int\)0\]: SUCCESS
5+
\[test.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed( long)* int\)10\]: FAILURE
66
^EXIT=10$
77
^SIGNAL=0$
88
--

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Diffblue Ltd.
1010

1111
#include <util/allocate_objects.h>
1212
#include <util/arith_tools.h>
13+
#include <util/c_types.h>
1314
#include <util/exception_utils.h>
1415
#include <util/std_code.h>
1516
#include <util/std_expr.h>
@@ -53,6 +54,8 @@ struct function_call_harness_generatort::implt
5354
std::map<irep_idt, irep_idt> function_argument_to_associated_array_size;
5455
std::map<irep_idt, irep_idt> function_parameter_to_associated_array_size;
5556

57+
std::set<symbol_exprt> global_pointers;
58+
5659
/// \see goto_harness_generatort::generate
5760
void generate(goto_modelt &goto_model, const irep_idt &harness_function_name);
5861
/// Iterate over the symbol table and generate initialisation code for
@@ -194,6 +197,11 @@ void function_call_harness_generatort::implt::generate(
194197

195198
generate_nondet_globals(function_body);
196199
call_function(arguments, function_body);
200+
for(const auto &global_pointer : global_pointers)
201+
{
202+
function_body.add(code_function_callt{
203+
recursive_initialization->get_free_function(), {global_pointer}});
204+
}
197205
add_harness_function_to_goto_model(std::move(function_body));
198206
}
199207

@@ -228,7 +236,10 @@ void function_call_harness_generatort::implt::generate_initialisation_code_for(
228236
code_blockt &block,
229237
const exprt &lhs)
230238
{
231-
recursive_initialization->initialize(lhs, 0, {}, block);
239+
recursive_initialization->initialize(
240+
lhs, from_integer(0, signed_int_type()), block);
241+
if(lhs.type().id() == ID_pointer)
242+
global_pointers.insert(to_symbol_expr(lhs));
232243
}
233244

234245
void function_call_harness_generatort::validate_options(
@@ -366,6 +377,8 @@ void function_call_harness_generatort::implt::call_function(
366377
for(auto const &argument : arguments)
367378
{
368379
generate_initialisation_code_for(function_body, argument);
380+
if(argument.type().id() == ID_pointer)
381+
global_pointers.insert(to_symbol_expr(argument));
369382
}
370383
code_function_callt function_call{function_to_call.symbol_expr(),
371384
std::move(arguments)};

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Author: Daniel Poetzl
1717

1818
#include <json-symtab-language/json_symbol_table.h>
1919

20+
#include <util/arith_tools.h>
21+
#include <util/c_types.h>
2022
#include <util/exception_utils.h>
2123
#include <util/fresh_symbol.h>
2224
#include <util/message.h>
@@ -290,7 +292,9 @@ code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
290292
else
291293
{
292294
recursive_initialization.initialize(
293-
fresh_or_snapshot_symbol.symbol_expr(), 0, {}, code);
295+
fresh_or_snapshot_symbol.symbol_expr(),
296+
from_integer(0, size_type()),
297+
code);
294298
}
295299
}
296300
return code;

0 commit comments

Comments
 (0)