Skip to content

Commit 974e078

Browse files
committed
Use get_fresh_aux_symbol to construct dynamic objects
This avoids use of a global variable and reuses central infrastructure instead of repeated local work. Note that this changes the names of dynamic objects as the suffix now includes a $ character, and need not have any suffix, as well as moving the counter out of the middle of C++/Java dynamic_X_array objects.
1 parent 6d3a9db commit 974e078

File tree

9 files changed

+62
-75
lines changed

9 files changed

+62
-75
lines changed

jbmc/regression/jbmc-generics/constant_propagation/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Test
33
--function Test.main --show-vcc
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\{-\d+\} symex_dynamic::dynamic_object1#2\.\.@Generic\.\[email protected]\.\.@class_identifier = "java::GenericSub"$
7-
^\{-\d+\} symex_dynamic::dynamic_object1#2\.\.@Generic\.\.key = NULL$
8-
^\{-\d+\} symex_dynamic::dynamic_object1#3\.\.@Generic\.\.x = 5$
6+
^\{-\d+\} symex_dynamic::dynamic_object#2\.\.@Generic\.\[email protected]\.\.@class_identifier = "java::GenericSub"$
7+
^\{-\d+\} symex_dynamic::dynamic_object#2\.\.@Generic\.\.key = NULL$
8+
^\{-\d+\} symex_dynamic::dynamic_object#3\.\.@Generic\.\.x = 5$
99
--
1010
byte_extract_(big|little)_endian
1111
--

jbmc/regression/jbmc-strings/long_string/test_abort.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test
33
--function Test.checkAbort --trace --max-nondet-string-length 100000000
44
^EXIT=10$
55
^SIGNAL=0$
6-
dynamic_object[0-9]*=\(assignment removed\)
6+
dynamic_object\$?[0-9]*=\(assignment removed\)
77
--
88
--
99
This tests that the object does not appear in the trace, because concretizing

jbmc/regression/jbmc/VarLengthArrayTrace1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VarLengthArrayTrace1
33
--trace --function VarLengthArrayTrace1.main
44
^EXIT=10$
55
^SIGNAL=0$
6-
dynamic_3_array\[1.*\]=10
6+
dynamic_array\$?\d*\[1.*\]=10
77
--
88
^warning: ignoring
99
assignment removed

jbmc/regression/jbmc/json_trace3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Test
44
activate-multi-line-match
55
^EXIT=10$
66
^SIGNAL=0$
7-
"lhs": "dynamic_object3\[1L?\]",\n *"mode": "java",\n *"sourceLocation": \{\n *"bytecodeIndex": "18",\n *"file": "Test\.java",\n *"function": "java::Test\.main:\(\[J\)V",\n *"line": "8"\n *\},\n *"stepType": "assignment",\n *"thread": 0,\n *"value": \{\n *"binary": "0000000000000000000000000000000000000000000000000000000000000001",\n *"data": "1L",\n *"name": "integer",\n *"type": "long",\n *"width": 64
7+
"lhs": "dynamic_object\$?\d*\[1L?\]",\n *"mode": "java",\n *"sourceLocation": \{\n *"bytecodeIndex": "18",\n *"file": "Test\.java",\n *"function": "java::Test\.main:\(\[J\)V",\n *"line": "8"\n *\},\n *"stepType": "assignment",\n *"thread": 0,\n *"value": \{\n *"binary": "0000000000000000000000000000000000000000000000000000000000000001",\n *"data": "1L",\n *"name": "integer",\n *"type": "long",\n *"width": 64
88
--
99
"name": "unknown"
1010
^warning: ignoring

regression/cbmc/trace-values/trace-values.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trace-values.c
1010
^ my_nested\[0.*\].array\[1.*\]=4 .*$
1111
^ my_nested\[1.*\].f=5 .*$
1212
^ junk\$object=7 .*$
13-
^ dynamic_object1\[1.*\]=8 .*$
13+
^ dynamic_object\[1.*\]=8 .*$
1414
^ my_nested\[1.*\](=\{ )?.f=0[ ,]
1515
^ my_nested\[1.*\](=\{ .f=0, )?.array=\{ 0, 4, 0 \}
1616
^ s\.f=42 \([0 ]+ 00101010\)$

src/goto-symex/auto_objects.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ Author: Daniel Kroening, [email protected]
1919

2020
exprt goto_symext::make_auto_object(const typet &type, statet &state)
2121
{
22-
dynamic_counter++;
23-
2422
// produce auto-object symbol
25-
symbolt symbol;
26-
27-
symbol.base_name="auto_object"+std::to_string(dynamic_counter);
28-
symbol.name="symex::"+id2string(symbol.base_name);
29-
symbol.is_lvalue=true;
30-
symbol.type=type;
31-
symbol.mode=ID_C;
32-
33-
state.symbol_table.add(symbol);
34-
35-
return symbol_exprt(symbol.name, symbol.type);
23+
symbolt &symbol = get_fresh_aux_symbol(
24+
type,
25+
"symex",
26+
"auto_object",
27+
state.source.pc->source_location,
28+
ID_C,
29+
state.symbol_table);
30+
symbol.is_thread_local = false;
31+
symbol.is_file_local = false;
32+
33+
return symbol.symbol_expr();
3634
}
3735

3836
void goto_symext::initialize_auto_object(const exprt &expr, statet &state)
@@ -86,7 +84,7 @@ void goto_symext::trigger_auto_object(const exprt &expr, statet &state)
8684
{
8785
const symbolt &symbol = ns.lookup(obj_identifier);
8886

89-
if(has_prefix(id2string(symbol.base_name), "auto_object"))
87+
if(has_prefix(id2string(symbol.base_name), "symex::auto_object"))
9088
{
9189
// done already?
9290
if(!state.get_level2().current_names.has_key(

src/goto-symex/goto_symex.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Author: Daniel Kroening, [email protected]
2929

3030
#include <climits>
3131

32-
unsigned goto_symext::dynamic_counter=0;
33-
3432
void goto_symext::do_simplify(exprt &expr)
3533
{
3634
if(symex_config.simplify_opt)

src/goto-symex/goto_symex.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,6 @@ class goto_symext
776776
/// \param code: The cleaned up output instruction
777777
virtual void symex_output(statet &state, const codet &code);
778778

779-
/// A monotonically increasing index for each created dynamic object
780-
static unsigned dynamic_counter;
781-
782779
void rewrite_quantifiers(exprt &, statet &);
783780

784781
/// \brief Symbolic execution paths to be resumed later

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ void goto_symext::symex_allocate(
5656
if(lhs.is_nil())
5757
return; // ignore
5858

59-
dynamic_counter++;
60-
6159
exprt size = to_binary_expr(code).op0();
6260
optionalt<typet> object_type;
6361
auto function_symbol = outer_symbol_table.lookup(state.source.function_id);
@@ -137,19 +135,16 @@ void goto_symext::symex_allocate(
137135
{
138136
exprt &array_size = to_array_type(*object_type).size();
139137

140-
auxiliary_symbolt size_symbol;
141-
142-
size_symbol.base_name=
143-
"dynamic_object_size"+std::to_string(dynamic_counter);
144-
size_symbol.name =
145-
SYMEX_DYNAMIC_PREFIX "::" + id2string(size_symbol.base_name);
146-
size_symbol.type=tmp_size.type();
147-
size_symbol.mode = mode;
138+
symbolt &size_symbol = get_fresh_aux_symbol(
139+
tmp_size.type(),
140+
SYMEX_DYNAMIC_PREFIX,
141+
"dynamic_object_size",
142+
code.source_location(),
143+
mode,
144+
state.symbol_table);
148145
size_symbol.type.set(ID_C_constant, true);
149146
size_symbol.value = array_size;
150147

151-
state.symbol_table.add(size_symbol);
152-
153148
auto array_size_rhs = array_size;
154149
array_size = size_symbol.symbol_expr();
155150

@@ -158,17 +153,17 @@ void goto_symext::symex_allocate(
158153
}
159154

160155
// value
161-
symbolt value_symbol;
162-
163-
value_symbol.base_name="dynamic_object"+std::to_string(dynamic_counter);
164-
value_symbol.name =
165-
SYMEX_DYNAMIC_PREFIX "::" + id2string(value_symbol.base_name);
166-
value_symbol.is_lvalue=true;
167-
value_symbol.type = *object_type;
156+
symbolt &value_symbol = get_fresh_aux_symbol(
157+
*object_type,
158+
SYMEX_DYNAMIC_PREFIX,
159+
"dynamic_object",
160+
code.source_location(),
161+
mode,
162+
state.symbol_table);
163+
value_symbol.is_auxiliary = false;
164+
value_symbol.is_thread_local = false;
165+
value_symbol.is_file_local = false;
168166
value_symbol.type.set(ID_C_dynamic, true);
169-
value_symbol.mode = mode;
170-
171-
state.symbol_table.add(value_symbol);
172167

173168
// to allow constant propagation
174169
exprt zero_init = state.rename(to_binary_expr(code).op1(), ns).get();
@@ -471,47 +466,46 @@ void goto_symext::symex_cpp_new(
471466
const exprt &lhs,
472467
const side_effect_exprt &code)
473468
{
474-
bool do_array;
475-
476-
PRECONDITION(code.type().id() == ID_pointer);
477-
478469
const auto &pointer_type = to_pointer_type(code.type());
479470

480-
do_array =
471+
const bool do_array =
481472
(code.get(ID_statement) == ID_cpp_new_array ||
482473
code.get(ID_statement) == ID_java_new_array_data);
483474

484-
dynamic_counter++;
485-
486-
const std::string count_string(std::to_string(dynamic_counter));
487-
488475
// value
489-
symbolt symbol;
490-
symbol.base_name=
491-
do_array?"dynamic_"+count_string+"_array":
492-
"dynamic_"+count_string+"_value";
493-
symbol.name = SYMEX_DYNAMIC_PREFIX "::" + id2string(symbol.base_name);
494-
symbol.is_lvalue=true;
495-
if(code.get(ID_statement)==ID_cpp_new_array ||
496-
code.get(ID_statement)==ID_cpp_new)
497-
symbol.mode=ID_cpp;
498-
else if(code.get(ID_statement) == ID_java_new_array_data)
499-
symbol.mode=ID_java;
500-
else
501-
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
502-
476+
optionalt<typet> type;
503477
if(do_array)
504478
{
505479
exprt size_arg =
506480
clean_expr(static_cast<const exprt &>(code.find(ID_size)), state, false);
507-
symbol.type = array_typet(pointer_type.base_type(), size_arg);
481+
type = array_typet(pointer_type.base_type(), size_arg);
508482
}
509483
else
510-
symbol.type = pointer_type.base_type();
484+
type = pointer_type.base_type();
511485

512-
symbol.type.set(ID_C_dynamic, true);
486+
irep_idt mode;
487+
if(
488+
code.get(ID_statement) == ID_cpp_new_array ||
489+
code.get(ID_statement) == ID_cpp_new)
490+
{
491+
mode = ID_cpp;
492+
}
493+
else if(code.get(ID_statement) == ID_java_new_array_data)
494+
mode = ID_java;
495+
else
496+
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
513497

514-
state.symbol_table.add(symbol);
498+
symbolt &symbol = get_fresh_aux_symbol(
499+
*type,
500+
SYMEX_DYNAMIC_PREFIX,
501+
(do_array ? "dynamic_array" : "dynamic_value"),
502+
code.source_location(),
503+
mode,
504+
state.symbol_table);
505+
symbol.is_auxiliary = false;
506+
symbol.is_thread_local = false;
507+
symbol.is_file_local = false;
508+
symbol.type.set(ID_C_dynamic, true);
515509

516510
// make symbol expression
517511

0 commit comments

Comments
 (0)