-fno-strict-aliasing in CWARNFLAGS?
mcree at orcon.net.nz
Wed Feb 3 12:02:29 PST 2010
On 04/02/10 07:55, Soeren Sandmann wrote:
> I recently turned it on in pixman because completely reasonable code
> like this:
> 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
> for (i = 0; i< width; i++)
> const uint8_t a = src[i]>> 56,
> r = src[i]>> 40,
> g = src[i]>> 24,
> b = src[i]>> 8;
> dst[i] = a<< 24 | r<< 16 | g<< 8 | b;
> 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?
What I do see is that the variables a, r, g and b are essentially
declared unsigned char (what I presume uint8_t is typedefed to) and a
calculation is performed that will lose its intended result due to
shifting an unsigned char more bits to the left than is available in the
unsigned char. I doubt that this code works as intended whether
-fno-strict-aliasing is defined or not!
More information about the xorg-devel