From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18381 invoked by alias); 9 Mar 2013 08:26:28 -0000 Received: (qmail 18262 invoked by uid 48); 9 Mar 2013 08:26:00 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/56576] wrong code for aliased union at -O3 Date: Sat, 09 Mar 2013 08:26: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2013-03/txt/msg00728.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56576 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek 2013-03-09 08:25:58 UTC --- This is IMHO just wrong code. C99 makes this undefined behavior of course, see ISO C99, 6.2.6.1/7: "When a value is stored in a member of an object of union type, the bytes of the object representation that do not correspond to that member but do correspond to other members take unspecified values, but the value of the union object shall not thereby become a trap representation." Now, while GCC allows some kind of type punning through unions, it doesn't allow everything, in particular the access has to be done through the union, not what you did, take pointers of the different union members and just access everything through the pointers - if GCC wanted to support that, it would simply has to give up on TBAA. Also, among the unsupported things are e.g. structure copies in between union members, consider say: struct S { long l[256]; }; union U { struct T { int i; struct S s; } t; struct S s; } u; ... u.s = u.t.s; or: u.t.s = u.s; or: struct S *p = &u.t.s; ... *p = u.s; or: struct S *p = &u.s; ... *p = u.t.s; will just not work properly (we generate memcpy even when there is overlap), because generally valid structure copies are either same address or without any overlap.