0

I want to model fixed-size arrays that can contain records and other fixed-size arrays. I then want to model store and select accesses to them.

I currently use ArraySorts for the arrays and Datatypes for the records. However, according to this answer (arrays) and this answer (records), these aren't really intended for my usecase. Is there anything else in Z3 I could use instead?


Background: I want to model pointers as they occur in the LLVM IR. For this, each pointer has a data array that represents the memory buffer into which it is pointing and an indices array that represents the indices used in getelementptr calls. Since the memory buffer could contain pointers or structs, I need to be able to nest the arrays (or store the records in arrays).

An example (in z3py) looks like this:

Vec3 = z3.Datatype("Vec3")
Vec3.declare("Vec3__init",
  ("x", z3.IntSort()),
  ("y", z3.IntSort()),
  ("z", z3.IntSort())
)
Vec3 = Vec3.create()

PointerVec3 = z3.Datatype("Pointer__Vec3")
PointerVec3.declare("Pointer__Vec3__init",
  ("data", z3.ArraySort(z3.BitVecSort(32), Vec3)),
  ("nindices", z3.IntSort()),
  ("indices", z3.ArraySort(z3.IntSort(), z3.BitVecSort(32)))
)
PointerVec3 = PointerVec3.create()
jazzpi
  • 1,399
  • 12
  • 18

1 Answers1

0

Arrays and records are the only way to model these things in z3/SMT-Lib. And they can be nested as you wish.

It is true that SMTLib arrays are not quite like arrays you find in regular programming languages. But it's not true that they are always unbounded. Their size exactly matches the cardinality of their domain. If you want a bounded array, I recommend using an appropriate BitVec type for your source. For an n-bit bit vector, your array will have 2^n elements. You can work with a small enough n, and treat that as your array; which typically matches what you see in practice: Most of such internal arrays will be a power-of-two anyhow. (Moreover, provers usually don't do well with large arrays; so sticking to a small power-of-two is a good idea, at least to start with.)

So, these are your only options. Stack-overflow works the best if you try it out and actually ask about what sort of problems you ran into.

alias
  • 28,120
  • 2
  • 23
  • 40