Comment 14 for bug 436758

On Mon, Oct 26, 2009 at 8:36 AM, Scott James Remnant <email address hidden>wrote:

> Ah, sorry, I meant alignof. From the gcc documentation it says that it
> returns on what byte boundary the object is aligned, not how much
> padding it needs:
>
>
Okay, my bad. I wonder how I didn't find that in the gcc docs.

> This implies that you do need to divide as I've done, so (correcting the
> code for my thinko):
>
> __alignof__ (struct) * ((sizeof (struct) - 1) / __alignof__ (struct)
> + 1)
>
> ie. the number of alignment segments required to fit the entire
> structure, plus padding
>
>
Okay, this looks good.

> That being said, I couldn't find any difference between the results of
> applying this code and not applying this code. The context block
> contains entirely pointers, which are the largest alignment anyway.
>
>
The problem with allocated blocks seems to not be with the returned pointer
directly, but with accessing fields in the returned block. I am assuming
from this that there's some extra-picky alignment that the internal pointers
need, but I really don't know enough sparc internals to say.

Your code would just change the aligned size from 40 to 48 and 20 to 24,
> which doesn't make any particular sense.
>
>
Yeah, I have no idea why 20 causes a SIGBUS (but, again, only when accessing
fields in a struct, not when using the returned pointer itself) and 24 is
fine.

> (Plus afaict, sizeof always includes the necessary padding to achieve
> alignment *anyway* - since otherwise malloc and arrays wouldn't work!)
>
>
Good point.

katre