[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: COPY_TWO_BYTES and C strict aliasing

From: Branko Čibej <brane_at_apache.org>
Date: Fri, 01 Jun 2012 14:47:45 +0200

On 01.06.2012 14:22, Philip Martin wrote:
> GCC gives a compiler warning where the COPY_TWO_BYTES macro is used. A
> typical warning is:
>
> ../src/subversion/libsvn_subr/string.c:971:11: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> COPY_TWO_BYTES(dest, decimal_table[(apr_size_t)number]);
> ^
[...]

> Is the warning something we can ignore? My understanding of C aliasing
> is that writing to memory is only supposed to happen as the declared
> type of that memory.
>
> Is COPY_TWO_BYTES a significant optimisation? On Linux we can avoid the
> warning by simply using
>
> memcpy(dest, source, 2)
>
> since that memcpy call will be inlined these days.
>

I think it's OK if that macro becomes an alias for memcpy. On modern
systems I'd even expect it to be faster than the current code, since a
properly inlined memcpy will know when to pick word-size over byte-size
operations, since it'll know the alignment of the source and target
(which this macro doesn't).

-- brane
Received on 2012-06-01 14:47:52 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.