@@ -337,23 +337,37 @@ class FatPointer extends TFatPointer {
337337
338338/**
339339 * A table with headers (start pointer, end pointer, source offset, sink offset, length).
340+ *
340341 * Consider the following code:
341342 * ``` C++
342- * int buf[10];
343- * int *p = buf;
344- * int *p2 = p - 5;
345- * int *p3 = p2 + 16;
343+ * int buf[10];
344+ * int *p = buf;
345+ * int *p2 = p - 5; // offshoots to left, totalOffset = -5
346+ * int *p3 = p2 + 16; // offshoots to right, totalOffset = 11
347+ * int *p4 = p3 - 2; // adjusts to left, totalOffset = 9
348+ * int *p5 = p4 - 5; // adjusts to left, totalOffset = 4
349+ * int *p6 = p5 - 5; // offshoots to left, totalOffset = -1
346350 * ```
347- * Then, this table is roughly populated with:
348- * |-------------+----------------+------------+-------------+----------------+------------------|
349- * | flow start | flow end | src offset | sink offset | length(exists) | valid? |
350- * |-------------+----------------+------------+-------------+----------------+------------------|
351- * | int buf[10] | p (∵ p - 5) | 0 | -5 | 10 | No, 0-5 < 10 |
352- * | p | p2 (∵ p2 + 12) | -5 | 12 | 10 | Yes, -5+12 < 10 |
353- * |-------------+----------------+------------+-------------+----------------+------------------|
351+ *
352+ * Then, this table is roughly populated with (we use PathNode src, sink instead of FatPointer
353+ * start, end for clarity):
354+ *
355+ * |-------------+----------------+-----------+------------+---------------+--------+------------|
356+ * | src | sink | srcOffset | sinkOffset | currentOffset | length | valid? |
357+ * |-------------+----------------+-----------+------------+---------------+--------+------------|
358+ * | def. of buf | p (∵ p - 5) | 0 | -5 | 0 - 5 = -5 | 10 | N, -5 < 0 |
359+ * | p - 5 | p2 (∵ p2 + 16) | -5 | 16 | -5 + 16 = 11 | 10 | N, 11 > 10 |
360+ * | p2 + 16 | p3 (∵ p3 - 2) | 16 | -2 | 11 - 2 = 9 | 10 | Y, 9 < 10 |
361+ * | p3 - 2 | p4 (∵ p4 - 5) | -2 | -5 | 9 - 5 = 4 | 10 | Y, 4 < 10 |
362+ * | p4 - 5 | p5 (∵ p5 - 5) | -5 | -5 | 4 - 5 = -1 | 10 | N, -1 < 0 |
363+ * |-------------+----------------+-----------+------------+---------------+--------+------------|
354364 *
355365 * And then we can answer the question of whether the pointer is valid (last column `valid?`).
356- * NOTE: Consult the configuration `TrackArrayConfig` for the actual definition of `src` and `sink`.
366+ *
367+ * The predicate also implements the following equations:
368+ *
369+ * - currentOffset_0 = srcOffset + sinkOffset if src is an ArrayAllocation
370+ * - currentOffset_{n} = currentOffset_{n-1} + sinkOffset if src is a PointerFormation
357371 */
358372predicate srcSinkLengthMap (
359373 FatPointer start , FatPointer end , int srcOffset , int sinkOffset , int currentOffset , int length
@@ -366,6 +380,7 @@ predicate srcSinkLengthMap(
366380 |
367381 srcOffset = start .getOffset ( ) and
368382 sinkOffset = end .getOffset ( ) and
383+ /* Implement the equation that computes the current offset. */
369384 (
370385 /* Base case: The object is allocated and a fat pointer created. */
371386 length = start .asAllocated ( ) .getLength ( src .getNode ( ) ) and
0 commit comments