Skip to content

Commit 9f81b13

Browse files
committed
Maintain nondet and dynamic counters across symex instances
Use the path storage, which maintains state across different symex instantiations. While at it, also make the counters std::size_t as using limited bitwidth is not a meaningful optimisation here.
1 parent d4cafdf commit 9f81b13

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

regression/cbmc/Bitfields3/paths.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check --paths lifo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cd regression/cbmc
44
rm Anonymous_Struct3/test.desc
55
rm Array_operations1/test.desc
66
rm Bitfields3/test.desc
7+
rm Bitfields3/paths.desc
78
rm Empty_struct1/test.desc
89
rm Endianness4/test.desc
910
rm Endianness6/test.desc

src/goto-symex/auto_objects.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ Author: Daniel Kroening, [email protected]
1818

1919
exprt goto_symext::make_auto_object(const typet &type, statet &state)
2020
{
21-
dynamic_counter++;
22-
2321
// produce auto-object symbol
2422
symbolt symbol;
2523

26-
symbol.base_name="auto_object"+std::to_string(dynamic_counter);
24+
symbol.base_name =
25+
"auto_object" + std::to_string(++path_storage.dynamic_counter);
2726
symbol.name="symex::"+id2string(symbol.base_name);
2827
symbol.is_lvalue=true;
2928
symbol.type=type;

src/goto-symex/goto_symex.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/simplify_expr.h>
1515

16-
unsigned goto_symext::nondet_count=0;
17-
unsigned goto_symext::dynamic_counter=0;
18-
1916
void goto_symext::do_simplify(exprt &expr)
2017
{
2118
if(symex_config.simplify_opt)
2219
simplify(expr, ns);
2320
}
2421

25-
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count)
22+
nondet_symbol_exprt build_symex_nondet(typet &type, std::size_t &nondet_count)
2623
{
2724
irep_idt identifier = "symex::nondet" + std::to_string(nondet_count++);
2825
nondet_symbol_exprt new_expr(identifier, type);

src/goto-symex/goto_symex.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +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 nondet_count;
412-
static unsigned dynamic_counter;
413-
414411
void rewrite_quantifiers(exprt &, statet &);
415412

416413
path_storaget &path_storage;
@@ -463,7 +460,7 @@ class goto_symext
463460
}
464461
};
465462

466-
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count);
463+
nondet_symbol_exprt build_symex_nondet(typet &type, std::size_t &nondet_count);
467464

468465
void symex_transition(goto_symext::statet &state);
469466

src/goto-symex/path_storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class path_storaget
8585
return size() == 0;
8686
};
8787

88+
/// Counters for nondet and dynamic objects, which require unique names
89+
std::size_t nondet_count;
90+
std::size_t dynamic_counter;
91+
8892
private:
8993
// Derived classes should override these methods, allowing the base class to
9094
// enforce preconditions.

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void goto_symext::symex_allocate(
5252
if(lhs.is_nil())
5353
return; // ignore
5454

55-
dynamic_counter++;
55+
const std::size_t dynamic_counter = ++path_storage.dynamic_counter;
5656

5757
exprt size=code.op0();
5858
optionalt<typet> object_type;
@@ -178,7 +178,8 @@ void goto_symext::symex_allocate(
178178
}
179179
else
180180
{
181-
const exprt nondet = build_symex_nondet(*object_type, nondet_count);
181+
const exprt nondet =
182+
build_symex_nondet(*object_type, path_storage.nondet_count);
182183
const code_assignt assignment(value_symbol.symbol_expr(), nondet);
183184
symex_assign(state, assignment);
184185
}
@@ -396,9 +397,8 @@ void goto_symext::symex_cpp_new(
396397
(code.get(ID_statement) == ID_cpp_new_array ||
397398
code.get(ID_statement) == ID_java_new_array_data);
398399

399-
dynamic_counter++;
400-
401-
const std::string count_string(std::to_string(dynamic_counter));
400+
const std::string count_string(
401+
std::to_string(++path_storage.dynamic_counter));
402402

403403
// value
404404
symbolt symbol;

src/goto-symex/symex_clean_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void adjust_byte_extract_rec(exprt &expr, const namespacet &ns)
160160
}
161161
}
162162

163-
static void replace_nondet(exprt &expr, unsigned &nondet_count)
163+
static void replace_nondet(exprt &expr, std::size_t &nondet_count)
164164
{
165165
if(expr.id() == ID_side_effect && expr.get(ID_statement) == ID_nondet)
166166
{
@@ -181,7 +181,7 @@ void goto_symext::clean_expr(
181181
statet &state,
182182
const bool write)
183183
{
184-
replace_nondet(expr, nondet_count);
184+
replace_nondet(expr, path_storage.nondet_count);
185185
dereference(expr, state, write);
186186

187187
// make sure all remaining byte extract operations use the root

0 commit comments

Comments
 (0)