This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/62171] restrict pointer to struct with restrict pointers parm doesn't prevent aliases
- From: "vries at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 22 Sep 2015 08:58:24 +0000
- Subject: [Bug tree-optimization/62171] restrict pointer to struct with restrict pointers parm doesn't prevent aliases
- Auto-submitted: auto-generated
- References: <bug-62171-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62171
--- Comment #8 from vries at gcc dot gnu.org ---
(In reply to Richard Biener from comment #7)
> I was thinking about sth like
>
> struct X { int i; int * __restrict__ q; };
>
> int foo (X& __restrict__ x, X *p)
> {
> *x.q = 1;
> p->i = 0;
> return *x.q;
> }
>
> int main()
> {
> X x;
> x.q = &x.i;
> return foo (x, &x);
> }
>
I think this example's an invalid use of restrict.
By using restrict in the 'X& __restrict__ x' parameter of foo, we promise that
if the object x points to is modified during foo execution (and it is, by both
assignments) we only access the object using pointers based on x during foo
execution.
p is pointing to the same object, and we access the object via p. But p is not
based on x.