<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 12/28/2016 5:41 AM, Hong Hu via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAC+VXiVQdKgEdo=qQxc=P1bK5m=bsTJ_h+rrccpKAJ+STYCLiA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-size:small">Hi all,</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" 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 class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" 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 class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" 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>
I would suggest converting the index of the struct GEP into an
offset in bytes; see StructLayout::getElementOffset. You can then
compare that to the layout of the original C++ class.<br>
<br>
-Eli<br>
<pre class="moz-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>
</body>
</html>