<div>Depending on your target, alignment may be increased by final code generation (IR -> native). Did you check final code?</div><div> </div><div>As radical measure you can hack your clang.</div><div> </div><div>Namely, artificially add "Aligned" attr to your structure declaration (which is CXXRecordDecl).</div><div> See "handleAlignedAttr" static method. And then "Sema::AddAlignedAttr". Latter should be called with some fake params, for it's not user defined.</div><div> </div><div>Or may be you could alter DataLayout for your target somehow.</div><div> </div><div>P.S.: If you're under C++11 or higher you always can use "alignas" in cpp code.</div><div>P.S.2: But the goal is weird. If I got right, you rely on target alignment and then fullfill gaps between structures with some data?</div><div> </div><div>Stepan Dyatkovskiy</div><div> </div><div>13.05.2019, 20:47, "Joan Lluch via cfe-dev" <cfe-dev@lists.llvm.org>:</div><blockquote><div style="word-wrap:break-word"><div>My target implementation has 2 byte (16 bit ints) </div><div>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> </div><div>The current situation is that for this struct:</div><div> </div><div>struct AA<br />{<!-- --><br />  char n;<br />  char m;<br />  char j;<br />};</div><div> </div><div>I get it aligned by 1:</div><div> </div><div>%a = alloca %struct.AA, align 1     </div><div> </div><div>I would want it to implicitly use 4 bytes instead of 3, (or it be aligned by 2 bytes instead of 1).</div><div> </div><div>If I replace the above struct by this:</div><div> </div><div>struct AA<br />{<!-- --><br />  int n;<br />  char m;<br />};</div><div> </div><div>or this:</div><div> </div><div>struct AA<br />{<!-- --><br />  char n;<br />  char m;<br />  char j;<br />  char k<br />};</div><div><br /> </div><div>I correctly get it aligned by 2:</div><div> </div><div>%a = alloca %struct.AA, align 2</div><div> </div><div>or:</div><div> </div><div>%a = alloca i32, align 2</div><div>%tmpcast = bitcast i32* %a to %struct.AA*</div><div> </div><div>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> </div><div>How do I change that behaviour to get structs always (at least) 2 byte aligned ?</div><div> </div><div><div style="color:rgb( 0 , 0 , 0 );text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="word-wrap:break-word"><div style="color:rgb( 0 , 0 , 0 );font-family:'helvetica';font-size:12px;font-style:normal;font-weight:normal;text-transform:none;white-space:normal;word-spacing:0px">John Lluch</div></div></div></div></div>,<p>_______________________________________________<br />cfe-dev mailing list<br /><a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br /><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></p></blockquote>