Skip to content

Commit 96c4752

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 2f1514e commit 96c4752

File tree

8 files changed

+63
-71
lines changed

8 files changed

+63
-71
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 & 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(
@@ -92,7 +91,7 @@ void goto_symext::trigger_auto_object(
9291
const symbolt &symbol=
9392
ns.lookup(obj_identifier);
9493

95-
if(has_prefix(id2string(symbol.base_name), "auto_object"))
94+
if(has_prefix(id2string(symbol.name), "symex::auto_object"))
9695
{
9796
// done already?
9897
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,6 @@ class goto_symext
403403
virtual void symex_input(statet &, const codet &);
404404
virtual void symex_output(statet &, const codet &);
405405

406-
static unsigned dynamic_counter;
407-
408406
void rewrite_quantifiers(exprt &, statet &);
409407

410408
path_storaget &path_storage;

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 44 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,16 @@ 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+
symbolt &size_symbol = get_fresh_aux_symbol(
133+
tmp_size.type(),
134+
"symex_dynamic",
135+
"dynamic_object_size",
136+
code.source_location(),
137+
mode,
138+
state.symbol_table);
140139
size_symbol.type.set(ID_C_constant, true);
141140
size_symbol.value = array_size;
142141

143-
state.symbol_table.add(size_symbol);
144-
145142
code_assignt assignment(size_symbol.symbol_expr(), array_size);
146143
array_size = assignment.lhs();
147144

@@ -150,16 +147,17 @@ void goto_symext::symex_allocate(
150147
}
151148

152149
// 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;
150+
symbolt &value_symbol = get_fresh_aux_symbol(
151+
*object_type,
152+
"symex_dynamic",
153+
"dynamic_object",
154+
code.source_location(),
155+
mode,
156+
state.symbol_table);
157+
value_symbol.is_auxiliary = false;
158+
value_symbol.is_thread_local = false;
159+
value_symbol.is_file_local = false;
159160
value_symbol.type.set(ID_C_dynamic, true);
160-
value_symbol.mode = mode;
161-
162-
state.symbol_table.add(value_symbol);
163161

164162
exprt zero_init=code.op1();
165163
state.rename(zero_init, ns); // to allow constant propagation
@@ -385,47 +383,46 @@ void goto_symext::symex_cpp_new(
385383
const exprt &lhs,
386384
const side_effect_exprt &code)
387385
{
388-
bool do_array;
389-
390-
PRECONDITION(code.type().id() == ID_pointer);
391-
392386
const auto &pointer_type = to_pointer_type(code.type());
393387

394-
do_array =
388+
const bool do_array =
395389
(code.get(ID_statement) == ID_cpp_new_array ||
396390
code.get(ID_statement) == ID_java_new_array_data);
397391

398-
dynamic_counter++;
399-
400-
const std::string count_string(std::to_string(dynamic_counter));
401-
402392
// value
403-
symbolt symbol;
404-
symbol.base_name=
405-
do_array?"dynamic_"+count_string+"_array":
406-
"dynamic_"+count_string+"_value";
407-
symbol.name="symex_dynamic::"+id2string(symbol.base_name);
408-
symbol.is_lvalue=true;
409-
if(code.get(ID_statement)==ID_cpp_new_array ||
410-
code.get(ID_statement)==ID_cpp_new)
411-
symbol.mode=ID_cpp;
412-
else if(code.get(ID_statement) == ID_java_new_array_data)
413-
symbol.mode=ID_java;
414-
else
415-
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
416-
393+
optionalt<typet> type;
417394
if(do_array)
418395
{
419396
exprt size_arg = static_cast<const exprt &>(code.find(ID_size));
420397
clean_expr(size_arg, state, false);
421-
symbol.type = array_typet(pointer_type.subtype(), size_arg);
398+
type = array_typet(pointer_type.subtype(), size_arg);
422399
}
423400
else
424-
symbol.type = pointer_type.subtype();
401+
type = pointer_type.subtype();
425402

426-
symbol.type.set(ID_C_dynamic, true);
403+
irep_idt mode;
404+
if(
405+
code.get(ID_statement) == ID_cpp_new_array ||
406+
code.get(ID_statement) == ID_cpp_new)
407+
{
408+
mode = ID_cpp;
409+
}
410+
else if(code.get(ID_statement) == ID_java_new_array_data)
411+
mode = ID_java;
412+
else
413+
INVARIANT_WITH_IREP(false, "Unexpected side effect expression", code);
427414

428-
state.symbol_table.add(symbol);
415+
symbolt &symbol = get_fresh_aux_symbol(
416+
*type,
417+
"symex_dynamic",
418+
(do_array ? "dynamic_array" : "dynamic_value"),
419+
code.source_location(),
420+
mode,
421+
state.symbol_table);
422+
symbol.is_auxiliary = false;
423+
symbol.is_thread_local = false;
424+
symbol.is_file_local = false;
425+
symbol.type.set(ID_C_dynamic, true);
429426

430427
// make symbol expression
431428

0 commit comments

Comments
 (0)