RE: Type Punning and -O3 on gcc 4.8.1 and 4.8.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have some code that computes a result from values in the type punning struct below. The struct is initialised with a 64 bit integer and the computations use the values of l1 and l2, i.e. it relies on type punning. The computation accesses all members via the union.

       struct pun {
                union {
                     struct {
                          uint32_t l1;
                            uint32_t l2;
                     };
                     uint64_t v;
                };
                pun (uint64_t v) : v(v) { }
           };

When I compile my code thus:

g++ -std=c++0x -g  -fnon-call-exceptions -fasynchronous-unwind-tables -ffast-math -msse4 -MMD -O3 -fno-threadsafe-statics -fno-omit-frame-pointer --param inline-unit-growth=70 -Wstrict-aliasing -Wformat -Werror=format -Wno-multichar -Werror=sequence-point -Werror=overflow -Werror=nonnull -Werror=return-type -Werror=unused-function -Werror=array-bounds

there are instances when the compiler chooses to pre-compute the value at compile time, which is nice. Unfortunately the resulting value doesn’t match the result of executing the same computation at run-time. It appears that the value at compile time is the value that would be derived if l2 (above) was zero rather than the non-zero value it takes in this instance.

I’ve read http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Optimize-Options.html#Type_002dpunning which I interpret as meaning the above is ok.

Is the above unsafe on gcc 4.8? Have I tripped up over a known issue?

Andy
GETCO Europe Limited (subsidiary of KCG Holdings, Inc.) is authorised and regulated by the Financial Conduct Authority. Registered Office 2nd Floor Vintners Place, 68 Upper Thames Street, London, EC4V 3BJ. Registered in England & Wales No. 04663084
This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link:

http://www.kcg.com/legal/global-disclosures





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux