Re: libalias patch for review / testing

From: Ruslan Ermilov <ru_at_freebsd.org>
Date: Wed, 17 Mar 2004 01:54:17 +0200
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

Received on Tue Mar 16 2004 - 14:54:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:47 UTC