Skip to content

Commit 138c675

Browse files
Add initialization of static arrays
Add non-det initialization of statically sized arrays. This does element-wise initialisation. Co-authored-by: Fotis Koutoulakis <[email protected]> Co-authored-by: Hannes Steffenhagen <[email protected]>
1 parent e639d76 commit 138c675

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
typedef struct st1
5+
{
6+
struct st2 *to_st2;
7+
int data;
8+
} st1_t;
9+
10+
typedef struct st2
11+
{
12+
struct st1 *to_st1;
13+
int data;
14+
} st2_t;
15+
16+
typedef struct st3
17+
{
18+
st1_t *array[3];
19+
} st3_t;
20+
21+
st1_t dummy1;
22+
st2_t dummy2;
23+
24+
void func(st3_t *p)
25+
{
26+
assert(p != NULL);
27+
for(int index = 0; index < 3; index++)
28+
{
29+
assert(p->array[index]->to_st2 != NULL);
30+
assert(p->array[index]->to_st2->to_st1 != NULL);
31+
assert(p->array[index]->to_st2->to_st1->to_st2 == NULL);
32+
}
33+
34+
assert(p->array[0] != p->array[1]);
35+
assert(p->array[1] != p->array[2]);
36+
assert(p->array[0] != p->array[2]);
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function func --min-null-tree-depth 10 --max-nondet-tree-depth 4 --harness-type call-function
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
^warning: ignoring

src/goto-harness/recursive_initialization.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Diffblue Ltd.
99
#include "recursive_initialization.h"
1010

1111
#include <util/allocate_objects.h>
12+
#include <util/arith_tools.h>
1213
#include <util/c_types.h>
1314
#include <util/fresh_symbol.h>
1415
#include <util/irep.h>
@@ -38,6 +39,10 @@ void recursive_initializationt::initialize(
3839
{
3940
initialize_pointer(lhs, depth, known_tags, body);
4041
}
42+
else if(type.id() == ID_array)
43+
{
44+
initialize_array(lhs, depth, known_tags, body);
45+
}
4146
else
4247
{
4348
initialize_nondet(lhs, depth, known_tags, body);
@@ -138,3 +143,23 @@ void recursive_initializationt::initialize_nondet(
138143
{
139144
body.add(code_assignt{lhs, side_effect_expr_nondett{lhs.type()}});
140145
}
146+
147+
void recursive_initializationt::initialize_array(
148+
const exprt &array,
149+
std::size_t depth,
150+
const recursion_sett &known_tags,
151+
code_blockt &body)
152+
{
153+
PRECONDITION(array.type().id() == ID_array);
154+
const auto &array_type = to_array_type(array.type());
155+
const auto array_size =
156+
numeric_cast_v<std::size_t>(to_constant_expr(array_type.size()));
157+
for(std::size_t index = 0; index < array_size; index++)
158+
{
159+
initialize(
160+
index_exprt(array, from_integer(index, size_type())),
161+
depth,
162+
known_tags,
163+
body);
164+
}
165+
}

src/goto-harness/recursive_initialization.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class recursive_initializationt
6969
std::size_t depth,
7070
const recursion_sett &known_tags,
7171
code_blockt &body);
72+
// array stuff
73+
// static array handling
74+
void initialize_array(
75+
const exprt &array,
76+
std::size_t depth,
77+
const recursion_sett &known_tags,
78+
code_blockt &body);
7279
};
7380

7481
#endif // CPROVER_GOTO_HARNESS_RECURSIVE_INITIALIZATION_H

0 commit comments

Comments
 (0)