Consider the following example source code. It demonstrates the aliasing relationship of the shown types when compiled with different levels of aliasing.
struct foo { int f1; int f2; int f3; } *fp; struct bar { int b1; int b2; int b3; } *bp;
If this example is compiled with the -xalias_level=any option, the compiler assumes the following alias information:
*fp, *bp, fp->f1, fp->f2, fp->f3, bp->b1, bp->b2 and bp->b3 all can alias each other because any two memory accesses alias each other at the level of -xalias_level=any.
If this example is compiled with the -xalias_level=basic option, the compiler assumes the following alias information:
*fp, *bp, fp->f1, fp->f2, fp->f3, bp->b1, bp->b2 and bp->b3 all can alias each other. Any two field accesses using pointers *fp and *bp can alias each other in this example because all the structure fields are the same basic type.
If this example is compiled with the -xalias_level=weak option, the compiler assumes the following alias information:
*fp and *fp can alias each other.
fp->f1 can alias bp->b1, *bp and *fp.
fp->f2 can alias bp->b2, *bp and *fp.
fp->f3 can alias bp->b3, *bp and *fp.
However, -xalias_level=weak imposes the following restrictions:
fp->f1 does not alias bp->b2 or bp->b3 because f1 has an offset of zero, which is different from that of b2 (four bytes) and b3 (eight bytes).
fp->f2 does not alias bp->b1 or bp->b3 because f2 has an offset of four bytes, which is different from b1 (zero bytes) and b3 (eight bytes).
fp->f3 does not alias bp->b1 or bp->b2 because f3 has an offset of eight bytes, which is different from b1 (zero bytes) and b2 (four bytes).
If this example is compiled with the -xalias_level=layout options, the compiler assumes the following alias information:
*fp and *bp can alias each other.
fp->f1 can alias bp->b1, *bp, and *fp.
fp->f2 can alias bp->b2, *bp, and *fp.
fp->f3 can alias bp->b3, *bp, and *fp.
However, -xalias_level=layout imposes the following restrictions:
fp->f1 does not alias bp->b2 or bp->b3 because field f1 corresponds to field b1 in the common initial sequence of foo and bar.
fp->f2 does not alias bp->b1 or bp->b3 because f2 corresponds to field b2 in the common initial sequence of foo and bar.
fp->f3 does not alias bp->b1 or bp->b2 because f3 corresponds to field b3 in the common initial sequence of foo and bar.
If this example is compiled with the -xalias_level=strict option, the compiler assumes the following alias information:
*fp and *bp can alias each other.
fp->f1 can alias bp->b1, *bp, and *fp.
fp->f2 can alias bp->b2, *bp, and *fp.
fp->f3 can alias bp->b3, *bp, and *fp.
However, -xalias_level=strict imposes the following restrictions:
fp->f1 does not alias bp->b2 or bp->b3 because field f1 corresponds to field b1 in the common initial sequence of foo and bar.
fp->f2 does not alias bp->b1 or bp->b3 because f2 corresponds to field b2 in the common initial sequence of foo and bar.
fp->f3 does not alias bp->b1 or bp->b2 because f3 corresponds to field b3 in the common initial sequence of foo and bar.
If this example is compiled with the -xalias_level=std option, the compiler assumes the following alias information:
fp->f1, fp->f2, fp->f3, bp->b1, bp->b2, and bp->b3 do not alias each other.
If this example is compiled with the -xalias_level=strong option, the compiler assumes the following alias information:
fp->f1, fp->f2, fp->f3, bp->b1, bp->b2, and bp->b3 do not alias each other.