https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67705
--- Comment #3 from vries at gcc dot gnu.org --- (In reply to Richard Biener from comment #2) > Indeed the wording contains "and X is also modified (by any means)." thus > fp == fp2 are valid even though they are marked restrict. Btw, lets forgo > the use of references here and talk plain C: > Agreed, that makes it easier to name the individual bits. > void > f (int *__restrict__ *__restrict__ fp, > int *__restrict__ *__restrict__ fp2) > { > int *p = *fp; // 1 > int *p2 = *fp2; // 2 > *p = 1; // 3 > *p2 = 2; // 4 > } > > void > g (int *__restrict__ gp) > { > f (gp, gp); After forgoing the references, that should be f (&gp, &gp); > } > > void > h (void) > { > int ha; > g (&ha); > } > > which better explains the issue you are rising. The standard doesn't talk > about stmts 1 and 2 (they do not modify anything). We are interested on > whether the writes 3 and 4 may alias or not. Agreed. > *p and *p2 would have to > be based on the same pointer: "Every other lvalue used to access the value > of X shall also have its address based on P." > I interpret this as follows. Restrict declaration D: "int *__restrict__ gp" Type T: int Object P: gp Block B: g function block Lvalues: *p and *p2 Objects designated by lvalues: ha in both cases. Object ha modified during execution of B: yes &Lvalues: pointer expressions p and p2 (or equivalently, pointer expressions *fp and *fp2) Now, the question is: are pointer expressions p and p2 based on gp? I think so. If we modify gp to point to a copy of ha before calling f in g, then both pointer expressions p and p2 (and *fp and *fp2) will change value. > The "pointer expression" here are *fp or *fp2 Agreed. > and either p needs to be > dependent on p2 or p2 needs to be dependent on p. > Both are not the > case IMHO They are indeed not dependent on each other, but I think that's not relevant. > - that both p and p2 are dependent on "*gp" does not count. I think what's relevant is that both pointer expressions p and p2 are based on object P gp. > I don't think writing > > **fp = 1; > **fp2 = 2; > > changes any of this. Agreed. > If it does then this is worth a DR I think. > I think the standard refers to 'P' as rvalue, The standard refers to P as a pointer object. > thus "modifying P > to point to a copy of the array object..." would not modify the lvalue *fp > but the rvalue *fp. > Modifying gp will modify pointer expressions p, p2, *fp and *fp2. The standard does not mention any distinction between lvalue or rvalue pointer expressions.