<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 30, 2015 at 11:33 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@gmail.com" target="_blank">rjmccall@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">rjmccall added a comment.<br>
<span class=""><br>
In <a href="http://reviews.llvm.org/D14980#298754" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14980#298754</a>, @rsmith wrote:<br>
<br>
> GCC's behavior (`aligned` on a field specifies the alignment of the start of that field) makes a little more sense to me than Clang's behavior (the type and alignment of a field specify a flavour of storage unit, and the field goes in the next such storage unit that it fits into), but both seem defensible.<br>
<br>
<br>
</span>Are you saying that `aligned` on a bit-field always starts new storage on GCC?</blockquote><div><br></div><div>Not exactly. For instance, given</div><div><br></div><div><div>struct X {</div><div>  __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2;</div><div>} x = {0, 1, 2, 3};</div></div><div><br></div><div>... GCC produces</div><div><br></div><div><div>x:</div><div>        .byte   0</div><div>        .byte   1</div><div>        .byte   2</div><div>        .byte   3</div></div><div><br></div><div>The result is the same for any other bit-field type (except that we get tail padding for types wider than 4 bytes), and in particular, we don't allocate a new storage unit for 'b' and 'd' when the type is 'short'; we just insert padding to get to a 1-byte-aligned boundary.</div><div><br></div><div>The rule that a bit-field can't straddle a naturally-aligned storage unit for the underlying type still applies (for non-packed structs). For instance,</div><div><br></div><div><div>struct Y {</div><div>  char : 1;</div><div>  __attribute__((aligned(1))) int n : 24;</div><div>} y = { 0x010203 };</div><div><br></div><div>struct Z {</div><div>  char : 1;</div><div>  __attribute__((aligned(1))) int n : 25;</div><div>} z = { 0x010203 };</div></div><div><br></div><div>gives:</div><div><br></div><div><div>y:</div><div>        .zero   1</div><div>        .byte   3</div><div>        .byte   2</div><div>        .byte   1</div><div>z:</div><div>        .zero   4</div><div>        .byte   3</div><div>        .byte   2</div><div>        .byte   1</div><div>        .byte   0</div></div><div><br></div><div>... and if the structs are packed, y is unchanged and z changes to this:</div><div><br></div><div><div>z:</div><div>        .zero   1</div><div>        .byte   3</div><div>        .byte   2</div><div>        .byte   1</div><div>        .byte   0</div></div></div></div></div>