<div dir="ltr">Hi Mats,<div><br></div><div>When the struct is packed, explicit byte array is introduced to pad the struct. (I saw this happened in clang 3.9.)</div><div><br></div><div>I want to check if a byte or byte array in an LLVM struct is introduce for explicit padding or not.</div><div><br></div><div>I don't need to worry about this problem in case the newest clang do not introduce byte array anymore.</div><div><br></div><div>Thanks</div><div>Hongbin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 18, 2017 at 1:03 AM, mats petersson <span dir="ltr"><<a href="mailto:mats@planetcatfish.com" target="_blank">mats@planetcatfish.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>What are you actually trying to achieve? LLVM knows the alignment and size of each component. You could iterate over the different types and identify when there is a difference in "calculated total size and the current alignment requirement", but LLVM does automatically pad structures [unless you specifically ask it not to].<br><br></div>Note that there is no actual field added for padding, it's just the size and alignment itself.<br><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 18 May 2017 at 08:51, Hongbin Zheng via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi Jonas,<div><br></div><div>Thanks a lot.</div><div>In an LLVM pass, how can I check the related information? will clang emit some metadata table?</div><div><br></div><div>Thanks</div><span class="m_5865314057619861833HOEnZb"><font color="#888888"><div>Hongbin</div></font></span></div><div class="m_5865314057619861833HOEnZb"><div class="m_5865314057619861833h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 18, 2017 at 12:47 AM, Jonas Devlieghere <span dir="ltr"><<a href="mailto:jonas@devlieghere.com" target="_blank">jonas@devlieghere.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default"><font face="tahoma, sans-serif" color="#20124d">Hi Hongbin,</font></div><div class="gmail_default"><font face="tahoma, sans-serif" color="#20124d"><br></font></div><div class="gmail_default"><font face="tahoma, sans-serif" color="#20124d">You can pass `-Wpadded` to clang. For your particular example it will print something along the lines of <br><br>```<br><div class="gmail_default">warning: padding struct 'foo1' with 7 bytes to align 'x' [-Wpadded]</div><div class="gmail_default"> long x;</div><div class="gmail_default">```</div><div class="gmail_default"><br></div><div class="gmail_default">Jonas</div></font></div><div class="gmail_extra">
<br><div class="gmail_quote"><div><div class="m_5865314057619861833m_5593048658879213703h5">On Thu, May 18, 2017 at 9:15 AM, Hongbin Zheng via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_5865314057619861833m_5593048658879213703h5"><div dir="ltr">Hi,<div><br></div><div>I am wondering how I can tell whether a field of a struct is introduced by padding or not.</div><div><br></div><div>For example, if I have a struct:</div><br>struct foo1 {<br> char *p; /* 8 bytes */<br> char c; /* 1 byte<br> long x; /* 8 bytes */<br>};<div><br></div><div>clang may generate:</div><br>struct foo1 {<br> char *p; /* 8 bytes */<br> char c; /* 1 byte<br> char pad[7]; /* 7 bytes */<br> long x; /* 8 bytes */<br>};<div><br></div><div>Is there any way that I can tell the "pad" array is generated by padding?</div><div><br></div><div>Thanks a lot</div><span class="m_5865314057619861833m_5593048658879213703m_-9083378872937218573HOEnZb"><font color="#888888"><div>Hongbin</div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></div><br></div></div>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>