This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization Problem With Data Conversion
- From: Ian Lance Taylor <iant at google dot com>
- To: Raymond Lu <songyulu at hdfgroup dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 08 May 2009 15:15:43 -0700
- Subject: Re: Optimization Problem With Data Conversion
- References: <4A049EC4.8090102@hdfgroup.org>
Raymond Lu <songyulu@hdfgroup.org> writes:
> Our HDF5 software has been having some data conversion problem with
> GCC's optimization for a few years. One example is to convert data
>>From short to int. You can find the program at
>
> ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/slu/tmp/ctest.c
>
> When I use "gcc -O2" or "gcc -O3" to compile it, I get wrong values
> after the conversion. When I use "gcc -O0" or "gcc -O1", the values
> are correct.
/* This line causes the trouble. */
*((int*)d) = (int)(*((short*)s));
This is an aliasing violation. Read the documentation for the
-fstrict-aliasing option.
Ian