Subject: Re: kern/34751: regular panics in tcp_sack_option on NetBSD/alpha 3.0_STABLE
To: None <netbsd-bugs@NetBSD.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 10/09/2006 05:40:11
Izumi Tsutsui wrote:
> The point is that gcc could optimize memcpy() to use normal
> load/store insns if the addresses are guranteed aligned.
> If you don't think it's valid, please consult gcc guys.

I know that C compilers optimize memcpy() in many ways as long
as they can prove all necessary requirements. Just imagine
that a cast to (u_int32_t *) masks out the lower 2 bits of
the pointer. That is a perfectly valid implementation and more
or less what happens in some hardware. It may cause a trap
or access memory in the wrong place. The problem is
that by forcefully casting a non-aligned pointer, you lie
to the compiler but it trusts you nonetheless. HAL 9000 is the
prototype of "undefined behaviour". 

-- 
Christian