This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/57359] wrong code for union access at -O3 on x86_64-linux


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]