This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/57359] wrong code for union access at -O3 on x86_64-linux
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 May 2013 18:33:18 +0000
- Subject: [Bug rtl-optimization/57359] wrong code for union access at -O3 on x86_64-linux
- Auto-submitted: auto-generated
- References: <bug-57359-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57359
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
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.