From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29572 invoked by alias); 12 Dec 2013 14:54: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 29549 invoked by uid 48); 12 Dec 2013 14:54:46 -0000 From: "soltys at ziu dot info" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59485] New: may_alias attribute ignored in internal references while defining aggregate types Date: Thu, 12 Dec 2013 14:54:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: soltys at ziu dot info X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: 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: 2013-12/txt/msg01064.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59485 Bug ID: 59485 Summary: may_alias attribute ignored in internal references while defining aggregate types Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: soltys at ziu dot info Note, I first asked about it on gcc-help, though got no responsens. This does look like a bug - though obviously I'm not sure if it really should be considered as such. Anyway, consider following piece of code: struct __attribute__((may_alias)) tag_si { int y; }; struct __attribute__((may_alias)) tag_s { int x; struct tag_si *pi; struct tag_s *p; }; int main(void) { struct tag_s test = {0}; struct tag_si **ppi; struct tag_s **pp; ppi = &test.pi; /* ok */ pp = &test.p; /* will generate warning */ return 0; } The possible problem with the above example, is that pp assignment will cause compiler to emit: test.c: In function 'main': test.c:18:12: warning: assignment from incompatible pointer type [enabled by default] pp = &test.p; ^ At the same time analogous ppi assignment gives no issues. The only difference between "tag_si" and "tag_s" is that the former is defined first outside and then referenced in subsequent definition - while the latter is referenced during its definition - and then it "forgets" about may_alias attribute (thus pp = &test.p gives warrning). I tried to workaround it with preceeding struct forward declaration, e.g. struct __attribute__((may_alias)) tag_s; struct __attribute__((may_alias)) tag_s { ...... But this approach has no effect either. The only workaround for that I found is extra typedef with may_alias and type cast, e.g.: typedef struct tag_s *tag_t_pa __attribute__((may_alias)); tag_t_pa *pp; pp = (tag_t_pa *)&test.p;