[OpenBIOS] Strict aliasing

Blue Swirl blauwirbel at gmail.com
Thu Aug 13 21:21:51 CEST 2009


On Tue, Aug 11, 2009 at 11:55 PM, Pavel Roskin<proski at gnu.org> wrote:
> Hello!
>
> The reason OpenBIOS violates the strict aliasing rules so often is
> because it uses char arrays to represent endian-specific data.
>
> Char arrays may have alignment different from that of the longer types.
> That's why casting a pointer to such array to a pointer to a longer type
> and dereferencing it is considered unsafe by the compiler.  The compiler
> assumes that different types would not occupy the same memory unless we
> tell it not to make such assumption.
>
> Char arrays serve as protection against misusing endian-specific data as
> host-endian integers.  The alternative it to use sparse annotated types,
> such as __le32.  __le32 has the same alignment as u32, but sparse would
> recognize attempts to use __le32 in arithmetic operations.
>
> I think switching to sparse annotated types would be a good idea whether
> strict aliasing is disabled or not.  It makes the code more readable.
> It could also fix some hard to find bugs.

Would it be possible and/or useful to use sparse types for cell types?



More information about the OpenBIOS mailing list