-fno-strict-aliasing in CWARNFLAGS?

Michael Cree mcree at orcon.net.nz
Wed Feb 3 12:49:41 PST 2010


On 04/02/10 09:17, Peter Harris wrote:
> 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.

Thanks, yes, it's now obvious.

Looking back at the code I now see that I completely missed the comment 
that says it is possible that src == dest.

When I read code and see two different pointer types in the functions 
arguments I naturally assume that it is _intended_ that they are two 
different areas of memory.  I always program like that and I guess that 
programming practice comes from once knowing the C standard well many 
years ago.

Cheers
Michael.


More information about the xorg-devel mailing list