Skip to content

Commit a6ef0d5

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 0e6538a commit a6ef0d5

File tree

8 files changed

+67
-70
lines changed

8 files changed

+67
-70
lines changed

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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ 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+
const std::string base_name = "auto_object";
24+
symbolt &symbol = get_fresh_aux_symbol(
25+
type,
26+
"symex::" + base_name,
27+
base_name,
28+
state.source.pc->source_location,
29+
ID_C,
30+
state.symbol_table);
31+
symbol.is_thread_local = false;
32+
symbol.is_file_local = false;
33+
34+
return symbol.symbol_expr();
3535
}
3636

3737
void goto_symext::initialize_auto_object(

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ class goto_symext
408408
virtual void symex_input(statet &, const codet &);
409409
virtual void symex_output(statet &, const codet &);
410410

411-
static unsigned dynamic_counter;
412-
413411
void rewrite_quantifiers(exprt &, statet &);
414412

415413
path_storaget &path_storage;

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 48 additions & 47 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>
@@ -52,8 +53,6 @@ void goto_symext::symex_allocate(
5253
if(lhs.is_nil())
5354
return; // ignore
5455

55-
dynamic_counter++;
56-
5756
exprt size=code.op0();
5857
optionalt<typet> object_type;
5958
auto function_symbol = outer_symbol_table.lookup(state.source.function_id);
@@ -130,18 +129,17 @@ void goto_symext::symex_allocate(
130129
{
131130
exprt &array_size = to_array_type(*object_type).size();
132131

133-
auxiliary_symbolt size_symbol;
134-
135-
size_symbol.base_name=
136-
"dynamic_object_size"+std::to_string(dynamic_counter);
137-
size_symbol.name="symex_dynamic::"+id2string(size_symbol.base_name);
138-
size_symbol.type=tmp_size.type();
139-
size_symbol.mode = mode;
132+
const std::string base_name = "dynamic_object_size";
133+
symbolt &size_symbol = get_fresh_aux_symbol(
134+
tmp_size.type(),
135+
"symex_dynamic::" + base_name,
136+
base_name,
137+
code.source_location(),
138+
mode,
139+
state.symbol_table);
140140
size_symbol.type.set(ID_C_constant, true);
141141
size_symbol.value = array_size;
142142

143-
state.symbol_table.add(size_symbol);
144-
145143
code_assignt assignment(size_symbol.symbol_expr(), array_size);
146144
array_size = assignment.lhs();
147145

@@ -150,16 +148,18 @@ void goto_symext::symex_allocate(
150148
}
151149

152150
// value
153-
symbolt value_symbol;
154-
155-
value_symbol.base_name="dynamic_object"+std::to_string(dynamic_counter);
156-
value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name);
157-
value_symbol.is_lvalue=true;
158-
value_symbol.type = *object_type;
151+
const std::string base_name = "dynamic_object";
152+
symbolt &value_symbol = get_fresh_aux_symbol(
153+
*object_type,
154+
"symex_dynamic::" + base_name,
155+
base_name,
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;
159162
value_symbol.type.set(ID_C_dynamic, true);
160-
value_symbol.mode = mode;
161-
162-
state.symbol_table.add(value_symbol);
163163

164164
exprt zero_init=code.op1();
165165
state.rename(zero_init, ns); // to allow constant propagation
@@ -386,47 +386,48 @@ void goto_symext::symex_cpp_new(
386386
const exprt &lhs,
387387
const side_effect_exprt &code)
388388
{
389-
bool do_array;
390-
391-
PRECONDITION(code.type().id() == ID_pointer);
392-
393389
const auto &pointer_type = to_pointer_type(code.type());
394390

395-
do_array =
391+
const bool do_array =
396392
(code.get(ID_statement) == ID_cpp_new_array ||
397393
code.get(ID_statement) == ID_java_new_array_data);
398394

399-
dynamic_counter++;
400-
401-
const std::string count_string(std::to_string(dynamic_counter));
402-
403395
// value
404-
symbolt symbol;
405-
symbol.base_name=
406-
do_array?"dynamic_"+count_string+"_array":
407-
"dynamic_"+count_string+"_value";
408-
symbol.name="symex_dynamic::"+id2string(symbol.base_name);
409-
symbol.is_lvalue=true;
410-
if(code.get(ID_statement)==ID_cpp_new_array ||
411-
code.get(ID_statement)==ID_cpp_new)
412-
symbol.mode=ID_cpp;
413-
else if(code.get(ID_statement) == ID_java_new_array_data)
414-
symbol.mode=ID_java;
415-
else
416-
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
417-
396+
optionalt<typet> type;
418397
if(do_array)
419398
{
420399
exprt size_arg = static_cast<const exprt &>(code.find(ID_size));
421400
clean_expr(size_arg, state, false);
422-
symbol.type = array_typet(pointer_type.subtype(), size_arg);
401+
type = array_typet(pointer_type.subtype(), size_arg);
423402
}
424403
else
425-
symbol.type = pointer_type.subtype();
404+
type = pointer_type.subtype();
426405

427-
symbol.type.set(ID_C_dynamic, true);
406+
std::string base_name = do_array ? "dynamic_array" : "dynamic_value";
428407

429-
state.symbol_table.add(symbol);
408+
irep_idt mode;
409+
if(
410+
code.get(ID_statement) == ID_cpp_new_array ||
411+
code.get(ID_statement) == ID_cpp_new)
412+
{
413+
mode = ID_cpp;
414+
}
415+
else if(code.get(ID_statement) == ID_java_new_array_data)
416+
mode = ID_java;
417+
else
418+
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
419+
420+
symbolt &symbol = get_fresh_aux_symbol(
421+
*type,
422+
"symex_dynamic::" + base_name,
423+
base_name,
424+
code.source_location(),
425+
mode,
426+
state.symbol_table);
427+
symbol.is_auxiliary = false;
428+
symbol.is_thread_local = false;
429+
symbol.is_file_local = false;
430+
symbol.type.set(ID_C_dynamic, true);
430431

431432
// make symbol expression
432433

0 commit comments

Comments
 (0)