<div dir="ltr"><div class="gmail_default" style="font-size:small">Add the example:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default" style="font-size:12.8px">class A {</div><div class="gmail_default" style="font-size:12.8px"> bool b1, b2;</div><div class="gmail_default" style="font-size:12.8px"> double d1;</div><div class="gmail_default" style="font-size:12.8px"> int i1;</div><div class="gmail_default" style="font-size:12.8px">}; </div><div class="gmail_default" style="font-size:12.8px"><br></div><div class="gmail_default" style="font-size:12.8px"><div style="font-size:12.8px">%class.A = type <{ i8, i8, [6 x i8], double, i32, [4 x i8] }><br></div><div><br></div></div></div><div class="gmail_extra"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Hu Hong</div></div></div></div>
<br><div class="gmail_quote">On 29 December 2016 at 10:57, Hong Hu <span dir="ltr"><<a href="mailto:huhong789@gmail.com" target="_blank">huhong789@gmail.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 style="font-size:small">Yes, Reid. I have used these methods to figure out the layout. </div><div style="font-size:small"><br></div><div style="font-size:small">Now my question is to build a map between the original layout and the new layout. I show one example below. When LLVM IR access the 4th (starting from 0th) member (i32) of the class A, the map will tell that in fact it is accessing the originally 3rd member (i1). Any suggestion?</div><div class="gmail_extra"><br clear="all"><div><div class="m_-3941619206828985389gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Hu Hong</div></div></div></div><div><div class="h5">
<br><div class="gmail_quote">On 29 December 2016 at 10:50, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.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">Only Clang really knows the original structure layout. You can pass '-Xclang -fdump-record-layouts', though, to see the layout during compilation. The DICompositeType metadata produced when compiling with debug info might contain enough information to describe the original layout.</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-3941619206828985389h5">On Wed, Dec 28, 2016 at 6:44 PM, Hong Hu 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_-3941619206828985389h5"><div dir="ltr"><div style="font-size:small">Thanks, Eli.</div><div style="font-size:small"><br></div><div style="font-size:small">Next question is how to get the layout of the original C++ class from LLVM IR? </div><div class="gmail_extra"><br clear="all"><div><div class="m_-3941619206828985389m_396961385618729735m_4423620293802935624gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Hu Hong</div></div></div></div><div><div class="m_-3941619206828985389m_396961385618729735h5">
<br><div class="gmail_quote">On 29 December 2016 at 01:57, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span>
<div class="m_-3941619206828985389m_396961385618729735m_4423620293802935624m_8347775751878978904moz-cite-prefix">On 12/28/2016 5:41 AM, Hong Hu via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div style="font-size:small">Hi all,</div>
<div style="font-size:small"><br>
</div>
<div style="font-size:small">I'm writing a
pass to understand the memory access to C++ class members. For
each GetElementPtr instruction, I check the second index to
the class pointer, to figure out which member it is intended
to access. </div>
<div style="font-size:small"><br>
</div>
<div style="font-size:small">However, due
to the structure padding, there are some fake members inserted
into the structure. For example, when GEP works on the 5th
element of the padded structure, it may in fact works on the
originally 3rd one, if there are two paddings before the
original 3rd member. </div>
<div style="font-size:small"><br>
</div>
<div style="font-size:small">Is there any
way to map this "5th" access to the original "3rd" one? For
example, some APIs to tell whether one member is a real
member, or a padded one?</div>
<br>
</div>
</blockquote>
<br></span>
I would suggest converting the index of the struct GEP into an
offset in bytes; see StructLayout::getElementOffset<wbr>. You can then
compare that to the layout of the original C++ class.<span class="m_-3941619206828985389m_396961385618729735m_4423620293802935624HOEnZb"><font color="#888888"><br>
<br>
-Eli<br>
<pre class="m_-3941619206828985389m_396961385618729735m_4423620293802935624m_8347775751878978904moz-signature" cols="72">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
</font></span></div>
</blockquote></div><br></div></div></div></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>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>