Skip to content

Commit 460db7b

Browse files
committed
Use allocate_objectst in the c nondet object factory
1 parent 7ec9fa5 commit 460db7b

File tree

3 files changed

+13
-57
lines changed

3 files changed

+13
-57
lines changed

regression/cbmc/pointer-function-parameters-2/test.desc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ main.c
33
--function fun --cover branch
44
^\*\* 7 of 7 covered \(100.0%\)$
55
^Test suite:$
6-
^a=\(\(signed int \*\*\)NULL\), tmp(\$\d+)?=[^,]*, tmp(\$\d+)?=[^,]*$
7-
^a=&tmp(\$\d+)?!0, tmp(\$\d+)?=\(\(signed int \*\)NULL\), tmp(\$\d+)?=[^,]*$
8-
^a=&tmp(\$\d+)?!0, tmp(\$\d+)?=&tmp\$\d+!0, tmp(\$\d+)?=(-[0-9]+|[012356789][0-9]*|4[0-9]+)$
9-
^a=&tmp(\$\d+)?!0, tmp(\$\d+)?=&tmp(\$\d+)?!0, tmp(\$\d+)?=4$
6+
^a=\(\(signed int \*\*\)NULL\), tmp_object_factory(\$\d+)?=[^,]*, tmp_object_factory(\$\d+)?=[^,]*$
7+
^a=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=\(\(signed int \*\)NULL\), tmp_object_factory(\$\d+)?=[^,]*$
8+
^a=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=&tmp_object_factory\$\d+!0, tmp_object_factory(\$\d+)?=(-[0-9]+|[012356789][0-9]*|4[0-9]+)$
9+
^a=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=4$
1010
^EXIT=0$
1111
^SIGNAL=0$
1212
--

regression/cbmc/pointer-function-parameters/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ main.c
33
--function fun --cover branch
44
^\*\* 5 of 5 covered \(100\.0%\)$
55
^Test suite:$
6-
^a=\(\(signed int \*\)NULL\), tmp(\$\d+)?=[^,]*$
7-
^a=&tmp(\$\d+)?!0, tmp(\$\d+)?=4$
8-
^a=&tmp(\$\d+)?!0, tmp(\$\d+)?=([012356789][0-9]*|4[0-9]+)$
6+
^a=\(\(signed int \*\)NULL\), tmp_object_factory(\$\d+)?=[^,]*$
7+
^a=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=4$
8+
^a=&tmp_object_factory(\$\d+)?!0, tmp_object_factory(\$\d+)?=([012356789][0-9]*|4[0-9]+)$
99
^EXIT=0$
1010
^SIGNAL=0$
1111
--

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Diffblue Ltd.
1313

1414
#include <ansi-c/c_object_factory_parameters.h>
1515

16+
#include <util/allocate_objects.h>
1617
#include <util/arith_tools.h>
1718
#include <util/c_types.h>
1819
#include <util/fresh_symbol.h>
@@ -47,62 +48,13 @@ class symbol_factoryt
4748
object_factory_params(object_factory_params)
4849
{}
4950

50-
exprt allocate_object(
51-
code_blockt &assignments,
52-
const exprt &target_expr,
53-
const typet &allocate_type,
54-
const bool static_lifetime);
55-
5651
void gen_nondet_init(
5752
code_blockt &assignments,
5853
const exprt &expr,
5954
const std::size_t depth = 0,
6055
recursion_sett recursion_set = recursion_sett());
6156
};
6257

63-
/// Create a symbol for a pointer to point to
64-
/// \param assignments: The code block to add code to
65-
/// \param target_expr: The expression which we are allocating a symbol for
66-
/// \param allocate_type: The type to use for the symbol. If this doesn't match
67-
/// target_expr then a cast will be used for the assignment
68-
/// \param static_lifetime: Whether the symbol created should have static
69-
/// lifetime
70-
/// \return Returns the address of the allocated symbol
71-
exprt symbol_factoryt::allocate_object(
72-
code_blockt &assignments,
73-
const exprt &target_expr,
74-
const typet &allocate_type,
75-
const bool static_lifetime)
76-
{
77-
symbolt &aux_symbol = get_fresh_aux_symbol(
78-
allocate_type,
79-
id2string(loc.get_function()),
80-
"tmp",
81-
loc,
82-
ID_C,
83-
symbol_table);
84-
aux_symbol.is_static_lifetime = static_lifetime;
85-
symbols_created.push_back(&aux_symbol);
86-
87-
const typet &allocate_type_resolved=ns.follow(allocate_type);
88-
const typet &target_type=ns.follow(target_expr.type().subtype());
89-
bool cast_needed=allocate_type_resolved!=target_type;
90-
91-
exprt aoe=address_of_exprt(aux_symbol.symbol_expr());
92-
if(cast_needed)
93-
{
94-
aoe=typecast_exprt(aoe, target_expr.type());
95-
}
96-
97-
// Add the following code to assignments:
98-
// <target_expr> = &tmp$<temporary_counter>
99-
code_assignt assign(target_expr, aoe);
100-
assign.add_source_location()=loc;
101-
assignments.add(std::move(assign));
102-
103-
return aoe;
104-
}
105-
10658
/// Creates a nondet for expr, including calling itself recursively to make
10759
/// appropriate symbols to point to if expr is a pointer.
10860
/// \param assignments: The code block to add code to
@@ -142,7 +94,11 @@ void symbol_factoryt::gen_nondet_init(
14294

14395
code_blockt non_null_inst;
14496

145-
exprt allocated=allocate_object(non_null_inst, expr, subtype, false);
97+
allocate_objectst allocate_objects(
98+
ID_C, loc, loc.get_function(), symbol_table);
99+
100+
exprt allocated = allocate_objects.allocate_non_dynamic_object(
101+
non_null_inst, expr, subtype, false, symbols_created);
146102

147103
exprt init_expr;
148104
if(allocated.id()==ID_address_of)

0 commit comments

Comments
 (0)