From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61974 invoked by alias); 22 Sep 2015 11:23:50 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 61678 invoked by uid 48); 22 Sep 2015 11:23:46 -0000 From: "vries at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/62171] restrict pointer to struct with restrict pointers parm doesn't prevent aliases Date: Tue, 22 Sep 2015 11:23:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-09/txt/msg01779.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62171 --- Comment #10 from vries at gcc dot gnu.org --- (In reply to rguenther@suse.de from comment #9) > On Tue, 22 Sep 2015, vries at gcc dot gnu.org wrote: > > > 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. > > Sorry, I modified it bogously, just move int i; out of the struct and > somewhere else. I don't understand. My reasoning above has nothing to do with 'int i'. > My concerns boil down to X being passed twice, > once as reference and once as pointer. That's exactly the thing I was trying to point out as illegal use of restrict. Let me try again, with variables renamed for clarity: struct X { int i; int * __restrict__ q; }; int foo (X& __restrict__ foox, X *foop) { *foox.q = 1; foop->i = 0; return *foox.q; } int main() { X mainx; mainx.q = &mainx.i; return foo (mainx, &mainx); } By: - using restrict for the foox parameter of foo, and - modifing object mainx during foo execution we promise that we only access the object mainx using pointers based on foox during foo execution. However, we access mainx via foop in foo, and foop is not based on foox.