<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">This has been tracked down to a bug in LLVM <span style="background-color: rgba(255, 255, 255, 0);">FindOptimalMemOpLowering function that affects all targets not supporting misaligned memory accesses (such as MSP430 and mips16)</span><div><br><div>The entire discussion starts here:</div><div><br></div><div><a href="http://lists.llvm.org/pipermail/llvm-dev/2019-May/132349.html">http://lists.llvm.org/pipermail/llvm-dev/2019-May/132349.html</a><br><br><div dir="ltr"><div><span style="background-color: rgba(255, 255, 255, 0);">John Lluch</span></div><div id="AppleMailSignature"><br></div></div><div dir="ltr"><br>On 16 May 2019, at 10:49, <a href="mailto:llvm@dyatkovskiy.com">llvm@dyatkovskiy.com</a> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><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" <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>>:</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></div></blockquote></div></div></body></html>