Skip to content

Commit 5ab4e4a

Browse files
authored
Merge pull request #4277 from NlightNFotis/fix-goto-harness-pointer-init
Fix: Do not nondet functions and fix scoping issue
2 parents b8678a4 + cefb1dd commit 5ab4e4a

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed

regression/goto-harness/chain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ if [ -e "${name}-mod.gb" ] ; then
2424
fi
2525

2626
$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
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
--
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
--

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,28 @@ void function_call_harness_generatort::implt::generate_nondet_globals(
182182
{
183183
if(nondet_globals)
184184
{
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>{};
185192
for(const auto &symbol_table_entry : *symbol_table)
186193
{
187194
const auto &symbol = symbol_table_entry.second;
188195
if(
189196
symbol.is_static_lifetime && symbol.is_lvalue &&
197+
symbol.type.id() != ID_code &&
190198
!has_prefix(id2string(symbol.name), CPROVER_PREFIX))
191199
{
192-
generate_initialisation_code_for(function_body, symbol.symbol_expr());
200+
globals.push_back(symbol.symbol_expr());
193201
}
194202
}
203+
for(auto const &global : globals)
204+
{
205+
generate_initialisation_code_for(function_body, global);
206+
}
195207
}
196208
}
197209

src/goto-harness/recursive_initialization.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ void recursive_initializationt::initialize_pointer(
9393
goto_model.symbol_table};
9494
exprt choice =
9595
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();
98107
allocate_objects.declare_created_symbols(body);
99108
body.add(code_assignt{lhs, null_pointer_exprt{type}});
100109
bool is_unknown_struct_tag =

0 commit comments

Comments
 (0)