Skip to content

Commit 85c963c

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 c436bd6 commit 85c963c

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
@@ -67,9 +67,20 @@ literalt arrayst::record_array_equality(
6767
collect_arrays(op0);
6868
collect_arrays(op1);
6969

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

75+
exprt arrayst::get(const exprt &expr) const
76+
{
77+
auto it = lhs_rhs_map.find(expr);
78+
if(it != lhs_rhs_map.end() && it->first != it->second)
79+
return get(it->second);
80+
else
81+
return SUB::get(expr);
82+
}
83+
7384
void arrayst::collect_indices()
7485
{
7586
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
@@ -46,6 +46,8 @@ class arrayst:public equalityt
4646
literalt record_array_equality(const equal_exprt &expr);
4747
void record_array_index(const index_exprt &expr);
4848

49+
exprt get(const exprt &expr) const override;
50+
4951
protected:
5052
const namespacet &ns;
5153

@@ -65,6 +67,7 @@ class arrayst:public equalityt
6567
// elements are added while references are held
6668
typedef std::list<array_equalityt> array_equalitiest;
6769
array_equalitiest array_equalities;
70+
std::unordered_map<exprt, exprt, irep_hash> lhs_rhs_map;
6871

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

src/solvers/strings/string_refinement.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ static optionalt<exprt> get_array(
977977
{
978978
const exprt &size = arr.length();
979979
exprt arr_val = simplify_expr(adjust_if_recursive(super_get(arr), ns), ns);
980+
if(arr_val.id() == ID_array)
981+
return std::move(arr_val);
980982
exprt size_val = super_get(size);
981983
size_val = simplify_expr(size_val, ns);
982984
const typet char_type = arr.type().subtype();

0 commit comments

Comments
 (0)