From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3089 invoked by alias); 21 May 2013 18:33:22 -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 3059 invoked by uid 48); 21 May 2013 18:33:18 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/57359] wrong code for union access at -O3 on x86_64-linux Date: Tue, 21 May 2013 18:33:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED 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: 2013-05/txt/msg01490.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57359 --- Comment #2 from Jakub Jelinek --- I think this testcase is invalid. C/C++ just disallow type punning through unions altogether (only one union member can be active at each point), while GCC allows it as an extension, it requires the accesses being done through the union, not through pointers to individual union fields. Quoting info gcc: " The practice of reading from a different union member than the one most recently written to (called "type-punning") is common. Even with `-fstrict-aliasing', type-punning is allowed, provided the memory is accessed through the union type. So, the code above will work as expected. *Note Structures unions enumerations and bit-fields implementation::. However, this code might not: int f() { union a_union t; int* ip; t.d = 3.0; ip = &t.i; return *ip; } ". But that is exactly what the testcase does, you have a pointer to u.ll and a pointer to u.i and use them interleaved. The code would be valid if la elements and k were pointers to the union and ppll pointer to pointer to the union, and accessed the i or ll fields in there.