Skip to content

Commit 65442e0

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 a350dc3 commit 65442e0

File tree

9 files changed

+65
-76
lines changed

9 files changed

+65
-76
lines changed

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

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

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.class
33
--function Test.checkAbort --trace
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.class
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.class
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
@@ -11,7 +11,7 @@ trace-values.c
1111
^ my_nested\[1.*\].f=5 .*$
1212
^ null\$object=6 .*$
1313
^ junk\$object=7 .*$
14-
^ dynamic_object1\[1.*\]=8 .*$
14+
^ dynamic_object\[1.*\]=8 .*$
1515
^ my_nested\[1.*\]=\{ .f=0, .array=\{ 0, 4, 0 \} \} .*$
1616
^VERIFICATION FAILED$
1717
--

src/goto-symex/auto_objects.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "goto_symex.h"
1313

14-
#include <util/prefix.h>
1514
#include <util/cprover_prefix.h>
16-
#include <util/symbol_table.h>
15+
#include <util/fresh_symbol.h>
16+
#include <util/prefix.h>
1717
#include <util/std_expr.h>
18+
#include <util/symbol_table.h>
1819

1920
exprt goto_symext::make_auto_object(const typet &type, statet &state)
2021
{
21-
dynamic_counter++;
22-
2322
// produce auto-object symbol
24-
symbolt symbol;
25-
26-
symbol.base_name="auto_object"+std::to_string(dynamic_counter);
27-
symbol.name="symex::"+id2string(symbol.base_name);
28-
symbol.is_lvalue=true;
29-
symbol.type=type;
30-
symbol.mode=ID_C;
31-
32-
state.symbol_table.add(symbol);
33-
34-
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();
3534
}
3635

3736
void goto_symext::initialize_auto_object(const exprt &expr, statet &state)
@@ -88,7 +87,7 @@ void goto_symext::trigger_auto_object(const exprt &expr, statet &state)
8887
const symbolt &symbol=
8988
ns.lookup(obj_identifier);
9089

91-
if(has_prefix(id2string(symbol.base_name), "auto_object"))
90+
if(has_prefix(id2string(symbol.name), "symex::auto_object"))
9291
{
9392
// done already?
9493
if(state.level2.current_names.find(ssa_expr.get_identifier())==

src/goto-symex/goto_symex.cpp

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

1414
#include <util/simplify_expr.h>
1515

16-
unsigned goto_symext::dynamic_counter=0;
17-
1816
void goto_symext::do_simplify(exprt &expr)
1917
{
2018
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
@@ -550,9 +550,6 @@ class goto_symext
550550
/// \param code: The cleaned up output instruction
551551
virtual void symex_output(statet &state, const codet &code);
552552

553-
/// A monotonically increasing index for each created dynamic object
554-
static unsigned dynamic_counter;
555-
556553
void rewrite_quantifiers(exprt &, statet &);
557554

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

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/arith_tools.h>
1515
#include <util/c_types.h>
1616
#include <util/expr_initializer.h>
17+
#include <util/fresh_symbol.h>
1718
#include <util/invariant_utils.h>
1819
#include <util/optional.h>
1920
#include <util/pointer_offset_size.h>
@@ -54,8 +55,6 @@ void goto_symext::symex_allocate(
5455
if(lhs.is_nil())
5556
return; // ignore
5657

57-
dynamic_counter++;
58-
5958
exprt size=code.op0();
6059
optionalt<typet> object_type;
6160
auto function_symbol = outer_symbol_table.lookup(state.source.function_id);
@@ -132,19 +131,16 @@ void goto_symext::symex_allocate(
132131
{
133132
exprt &array_size = to_array_type(*object_type).size();
134133

135-
auxiliary_symbolt size_symbol;
136-
137-
size_symbol.base_name=
138-
"dynamic_object_size"+std::to_string(dynamic_counter);
139-
size_symbol.name =
140-
SYMEX_DYNAMIC_PREFIX "::" + id2string(size_symbol.base_name);
141-
size_symbol.type=tmp_size.type();
142-
size_symbol.mode = mode;
134+
symbolt &size_symbol = get_fresh_aux_symbol(
135+
tmp_size.type(),
136+
SYMEX_DYNAMIC_PREFIX,
137+
"dynamic_object_size",
138+
code.source_location(),
139+
mode,
140+
state.symbol_table);
143141
size_symbol.type.set(ID_C_constant, true);
144142
size_symbol.value = array_size;
145143

146-
state.symbol_table.add(size_symbol);
147-
148144
code_assignt assignment(size_symbol.symbol_expr(), array_size);
149145
array_size = assignment.lhs();
150146

@@ -153,17 +149,17 @@ void goto_symext::symex_allocate(
153149
}
154150

155151
// value
156-
symbolt value_symbol;
157-
158-
value_symbol.base_name="dynamic_object"+std::to_string(dynamic_counter);
159-
value_symbol.name =
160-
SYMEX_DYNAMIC_PREFIX "::" + id2string(value_symbol.base_name);
161-
value_symbol.is_lvalue=true;
162-
value_symbol.type = *object_type;
152+
symbolt &value_symbol = get_fresh_aux_symbol(
153+
*object_type,
154+
SYMEX_DYNAMIC_PREFIX,
155+
"dynamic_object",
156+
code.source_location(),
157+
mode,
158+
state.symbol_table);
159+
value_symbol.is_auxiliary = false;
160+
value_symbol.is_thread_local = false;
161+
value_symbol.is_file_local = false;
163162
value_symbol.type.set(ID_C_dynamic, true);
164-
value_symbol.mode = mode;
165-
166-
state.symbol_table.add(value_symbol);
167163

168164
// to allow constant propagation
169165
exprt zero_init = state.rename(code.op1(), ns);
@@ -383,47 +379,46 @@ void goto_symext::symex_cpp_new(
383379
const exprt &lhs,
384380
const side_effect_exprt &code)
385381
{
386-
bool do_array;
387-
388-
PRECONDITION(code.type().id() == ID_pointer);
389-
390382
const auto &pointer_type = to_pointer_type(code.type());
391383

392-
do_array =
384+
const bool do_array =
393385
(code.get(ID_statement) == ID_cpp_new_array ||
394386
code.get(ID_statement) == ID_java_new_array_data);
395387

396-
dynamic_counter++;
397-
398-
const std::string count_string(std::to_string(dynamic_counter));
399-
400388
// value
401-
symbolt symbol;
402-
symbol.base_name=
403-
do_array?"dynamic_"+count_string+"_array":
404-
"dynamic_"+count_string+"_value";
405-
symbol.name = SYMEX_DYNAMIC_PREFIX "::" + id2string(symbol.base_name);
406-
symbol.is_lvalue=true;
407-
if(code.get(ID_statement)==ID_cpp_new_array ||
408-
code.get(ID_statement)==ID_cpp_new)
409-
symbol.mode=ID_cpp;
410-
else if(code.get(ID_statement) == ID_java_new_array_data)
411-
symbol.mode=ID_java;
412-
else
413-
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
414-
389+
optionalt<typet> type;
415390
if(do_array)
416391
{
417392
exprt size_arg = static_cast<const exprt &>(code.find(ID_size));
418393
clean_expr(size_arg, state, false);
419-
symbol.type = array_typet(pointer_type.subtype(), size_arg);
394+
type = array_typet(pointer_type.subtype(), size_arg);
420395
}
421396
else
422-
symbol.type = pointer_type.subtype();
397+
type = pointer_type.subtype();
423398

424-
symbol.type.set(ID_C_dynamic, true);
399+
irep_idt mode;
400+
if(
401+
code.get(ID_statement) == ID_cpp_new_array ||
402+
code.get(ID_statement) == ID_cpp_new)
403+
{
404+
mode = ID_cpp;
405+
}
406+
else if(code.get(ID_statement) == ID_java_new_array_data)
407+
mode = ID_java;
408+
else
409+
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
425410

426-
state.symbol_table.add(symbol);
411+
symbolt &symbol = get_fresh_aux_symbol(
412+
*type,
413+
SYMEX_DYNAMIC_PREFIX,
414+
(do_array ? "dynamic_array" : "dynamic_value"),
415+
code.source_location(),
416+
mode,
417+
state.symbol_table);
418+
symbol.is_auxiliary = false;
419+
symbol.is_thread_local = false;
420+
symbol.is_file_local = false;
421+
symbol.type.set(ID_C_dynamic, true);
427422

428423
// make symbol expression
429424

0 commit comments

Comments
 (0)