Skip to content

Commit 90c4a75

Browse files
committed
Add arrayst::get to return RHS of unbounded arrays
In order to generate a trace value for an unbounded LHS we may need to look at its RHS as (string) refinement may have constructed values for the RHS.
1 parent 9670fcc commit 90c4a75

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class Test {
2+
public String foo() {
3+
final int i = 10;
4+
final String retval = Integer.toHexString(i);
5+
assert(false);
6+
return retval;
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
Test.class
3+
--function Test.foo --trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
dynamic_object1=\{ 'a' \}
7+
--
8+
--
9+
Nondet propagation would previously cause an output like
10+
dynamic_object1=dynamic_object1#2, because the mapping between dynamic_object1#2
11+
and a nondet-symbol, which was otherwise being used by the string solver, was
12+
not established.

src/solvers/flattening/arrays.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,20 @@ literalt arrayst::record_array_equality(
6868
collect_arrays(op0);
6969
collect_arrays(op1);
7070

71+
lhs_rhs_map.emplace(op0, op1);
72+
7173
return array_equalities.back().l;
7274
}
7375

76+
exprt arrayst::get(const exprt &expr) const
77+
{
78+
auto it = lhs_rhs_map.find(expr);
79+
if(it != lhs_rhs_map.end() && it->first != it->second)
80+
return get(it->second);
81+
else
82+
return SUB::get(expr);
83+
}
84+
7485
void arrayst::collect_indices()
7586
{
7687
for(std::size_t i=0; i<arrays.size(); i++)

src/solvers/flattening/arrays.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class arrayst:public equalityt
4343
literalt record_array_equality(const equal_exprt &expr);
4444
void record_array_index(const index_exprt &expr);
4545

46+
exprt get(const exprt &expr) const override;
47+
4648
protected:
4749
const namespacet &ns;
4850

@@ -62,6 +64,7 @@ class arrayst:public equalityt
6264
// elements are added while references are held
6365
typedef std::list<array_equalityt> array_equalitiest;
6466
array_equalitiest array_equalities;
67+
std::unordered_map<exprt, exprt, irep_hash> lhs_rhs_map;
6568

6669
// this is used to find the clusters of arrays being compared
6770
union_find<exprt> arrays;

src/solvers/strings/string_refinement.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ static optionalt<exprt> get_array(
964964
const auto eom = messaget::eom;
965965
const exprt &size = arr.length();
966966
exprt arr_val = simplify_expr(adjust_if_recursive(super_get(arr), ns), ns);
967+
if(arr_val.id() == ID_array)
968+
return std::move(arr_val);
967969
exprt size_val = super_get(size);
968970
size_val = simplify_expr(size_val, ns);
969971
const typet char_type = arr.type().subtype();

0 commit comments

Comments
 (0)