-fno-strict-aliasing in CWARNFLAGS?
Peter Harris
pharris at opentext.com
Wed Feb 3 12:17:28 PST 2010
On 2010-02-03 15:02, Michael Cree wrote:
> On 04/02/10 07:55, Soeren Sandmann wrote:
>>
>> I recently turned it on in pixman because completely reasonable code
>> like this:
>>
>> void
>> pixman_contract (uint32_t * dst,
>> const uint64_t *src,
>> int width)
>> {
>> int i;
>>
>> /* Start at the beginning so that we can do the contraction in
>> * place when src == dst
>> */
>> is actually illegal under the C aliasing rules, and GCC can and will
>> break it unless you use -fno-strict-aliasing.
>
> I'm confused. Why does this break the aliasing rules?
If *dst and *src point to (alias) the same memory, it breaks the rules
since they are different types. The compiler is free to assume that dst
and src are disjoint. It may eg. unroll the loop and re-order the loads
and stores, resulting in something the programmer didn't expect if they
do overlap.
Peter Harris
--
Open Text Connectivity Solutions Group
Peter Harris http://connectivity.opentext.com/
Research and Development Phone: +1 905 762 6001
pharris at opentext.com Toll Free: 1 877 359 4866
More information about the xorg-devel
mailing list