Skip to content

Commit b19b412

Browse files
committed
Support address-of over arrays with non-constant element size
We can safely compute the (symbolic) offset in that case.
1 parent f12bf55 commit b19b412

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/solvers/flattening/bv_pointers.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ optionalt<bvt> bv_pointerst::convert_address_of_rec(const exprt &expr)
264264
UNREACHABLE;
265265

266266
// get size
267-
auto size = pointer_offset_size(array_type.element_type(), ns);
268-
CHECK_RETURN(size.has_value() && *size >= 0);
267+
auto size = size_of_expr(array_type.element_type(), ns);
268+
CHECK_RETURN(size.has_value());
269269

270270
bv = offset_arithmetic(type, bv, *size, index);
271271
CHECK_RETURN(bv.size()==bits);
@@ -844,6 +844,28 @@ bvt bv_pointerst::offset_arithmetic(
844844
return offset_arithmetic(type, bv, factor, bv_index);
845845
}
846846

847+
bvt bv_pointerst::offset_arithmetic(
848+
const pointer_typet &type,
849+
const bvt &bv,
850+
const exprt &factor,
851+
const exprt &index)
852+
{
853+
bvt bv_factor = convert_bv(factor);
854+
bvt bv_index =
855+
convert_bv(typecast_exprt::conditional_cast(index, factor.type()));
856+
857+
bv_utilst::representationt rep = factor.type().id() == ID_signedbv
858+
? bv_utilst::representationt::SIGNED
859+
: bv_utilst::representationt::UNSIGNED;
860+
861+
bv_index = bv_utils.multiplier(bv_index, bv_factor, rep);
862+
863+
const std::size_t offset_bits = get_offset_width(type);
864+
bv_index = bv_utils.extension(bv_index, offset_bits, rep);
865+
866+
return offset_arithmetic(type, bv, 1, bv_index);
867+
}
868+
847869
bvt bv_pointerst::offset_arithmetic(
848870
const pointer_typet &type,
849871
const bvt &bv,

src/solvers/flattening/bv_pointers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class bv_pointerst:public boolbvt
6666
const mp_integer &factor,
6767
const exprt &index);
6868
NODISCARD
69+
bvt offset_arithmetic(
70+
const pointer_typet &type,
71+
const bvt &bv,
72+
const exprt &factor,
73+
const exprt &index);
74+
NODISCARD
6975
bvt offset_arithmetic(
7076
const pointer_typet &,
7177
const bvt &,

0 commit comments

Comments
 (0)