MemRef descriptors contain - among others - a field called alignedPtr or data and a field called offset. The actual buffer of the MemRef starts at offset elements after alignedPtr. In the CRunnerUtils, there exist helper classes to iterate over MemRefs' elements but the offset is not handled consistently so that accessing a MemRef with an offset != 0 via an iterator will lead to incorrect results.
The problem is that "offset" can be understood in two ways, firstly as the offset of the beginning of the MemRef with respect to the alignedPtr, ie what the offset field means in the MemRef descriptor, and secondly as the offset of some element within the MemRef relative to the first element of the MemRef, which could more accurately be called something like linearIndex.
The offset field within StridedMemRefIterator and DynamicMemRefIterator are interpreted the first way, therefore the offsets passed to the constructors of these classes need to account for the already existing offset in the descriptor on top of any potential "shift" within the MemRef.
This patch takes care of that and adds some basic tests that catch problems with indexing MemRefs with an offset.