libalias patch for review / testing
Ruslan Ermilov
ru at freebsd.org
Tue Mar 16 15:54:16 PST 2004
On Wed, Mar 17, 2004 at 12:34:46AM +0100, Dag-Erling Sm?rgrav wrote:
> Ruslan Ermilov <ru at freebsd.org> writes:
> > : `-fstrict-aliasing'
> > : Allows the compiler to assume the strictest aliasing rules
> > : applicable to the language being compiled. For C (and C++), this
> > : activates optimizations based on the type of expressions. In
> > : particular, an object of one type is assumed never to reside at
> > : the same address as an object of a different type, unless the
> > : types are almost the same. For example, an `unsigned int' can
> > : alias an `int', but not a `void*' or a `double'. A character type
> > : may alias any other type.
> >
> > And asking myself a question: should those (void *)'s in your patch
> > be (char *)'s instead, e.g., in twowords() and DifferentialChecksum(),
> > or am I misreading the above?
>
> You're misreading, we're doing u_short * <-> void * (both pointers)
> but the man page speaks about int <-> void * (scalar vs pointer)
>
OK, I stand corrected. ;)
> Also, I doubt DifferentialChecksum() is a problem, since it's a
> function call. I think the problem may be in the code I've replaced
> with calls to twowords().
>
Hmm, now that I think about it more, since -O2 turns -fstrict-aliasing,
and the latter may produce broken code if strict aliasing rules are
broken by the source, I think people (and tinderboxes!) should compile
with ``-O2 -Wstrict-aliasing'' in CFLAGS rather than just -O2. For
WARNS > 1 compiled code, this will be a no-op (as -Wall implies
-Wstrict-aliasing), but it should help catch bugs related to breaking
strict aliasing like in libalias, in code that is otherwise compiled
without warnings.
Cheers,
--
Ruslan Ermilov
FreeBSD committer
ru at FreeBSD.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20040317/33d32832/attachment.bin
More information about the freebsd-net
mailing list