<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">My target implementation has 2 byte (16 bit ints) </div><div class="">For my target implementation I would want that Clang would always use at least 2 byte aligned padding for Structs, which would match the size of an int. </div><div class=""><br class=""></div><div class="">The current situation is that for this struct:</div><div class=""><br class=""></div><div class="">struct AA<br class="">{<br class="">  char n;<br class="">  char m;<br class="">  char j;<br class="">};</div><div class=""><br class=""></div><div class="">I get it aligned by 1:</div><div class=""><br class=""></div><div class="">%a = alloca %struct.AA, align 1     </div><div class=""><br class=""></div><div class="">I would want it to implicitly use 4 bytes instead of 3, (or it be aligned by 2 bytes instead of 1).</div><div class=""><br class=""></div><div class="">If I replace the above struct by this:</div><div class=""><br class=""></div><div class="">struct AA<br class="">{<br class="">  int n;<br class="">  char m;<br class="">};</div><div class=""><br class=""></div><div class="">or this:</div><div class=""><br class=""></div><div class="">struct AA<br class="">{<br class="">  char n;<br class="">  char m;<br class="">  char j;<br class="">  char k<br class="">};</div><div class=""><br class=""><br class=""></div><div class="">I correctly get it aligned by 2:</div><div class=""><br class=""></div><div class="">%a = alloca %struct.AA, align 2</div><div class=""><br class=""></div><div class="">or:</div><div class=""><br class=""></div><div class="">%a = alloca i32, align 2</div><div class="">%tmpcast = bitcast i32* %a to %struct.AA*</div><div class=""><br class=""></div><div class="">In summary, I noticed that Clang will compute struct alignments as an int (2 bytes) if it has one, or if the struct size is already a multiple of 2, but not in other cases.</div><div class=""><br class=""></div><div class="">How do I change that behaviour to get structs always (at least) 2 byte aligned ?</div><div class=""><br class=""></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">John Lluch</div></div></div>
</div>
<br class=""></body></html>