<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 03/29/2014 07:26 PM, David Blaikie
wrote:<br>
</div>
<blockquote
cite="mid:CAENS6Eujssk3TvSQtVTib-FoU8Lt7XLOQPRObnts3tbzKFN32A@mail.gmail.com"
type="cite">
<pre wrap="">On Sat, Mar 29, 2014 at 3:55 PM, Tehila Mayzels
<a class="moz-txt-link-rfc2396E" href="mailto:tehila@cs.technion.ac.il"><tehila@cs.technion.ac.il></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
Suppose I have a pointer to "something" (a structure I defined) and I want
to pass the pointer to a generic function, that gets a 64-bit address
pointer.
How do I do that?
For instance:
The function is:
void Foo (void *);
I get the specific pointer using getPointerOperand() on a store instruction
that store to it:
inst->getPointerOperand()->getType()
Now I want to call Foo with the pointer, but the types of the arguments are
mismatches - one is specific (%"class.XXX::YYY"*) and the other generic.
How should I cast it so there won't be a mismatch?
</pre>
</blockquote>
<pre wrap="">
Perhaps compiling similar code with Clang and looking at Clang's
generated IR would give you some insight into how that might be done.
</pre>
</blockquote>
Plugging<br>
<br>
void foo(void *p)<br>
{<br>
}<br>
<br>
int main()<br>
{<br>
struct foo { int a; } fum;<br>
foo(&fum);<br>
}<br>
<br>
into
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a href="http://ellcc.org/blog/?page_id=340">http://ellcc.org/blog/?page_id=340</a>
(the demo) with optimization set to none and selecting "LLVM C++ API
code" gives (among a lot of other stuff):<br>
<br>
// Function: main (func_main)<br>
{<br>
<br>
BasicBlock* label_entry_10 =
BasicBlock::Create(mod->getContext(), "entry",func_main,0);<br>
<br>
// Block entry (label_entry_10)<br>
AllocaInst* ptr_fum = new AllocaInst(StructTy_struct_foo, "fum",
label_entry_10);<br>
ptr_fum->setAlignment(4);<br>
CastInst* ptr_11 = new BitCastInst(ptr_fum, PointerTy_1, "",
label_entry_10);<br>
CallInst* void_12 = CallInst::Create(func_foo, ptr_11, "",
label_entry_10);<br>
void_12->setCallingConv(CallingConv::C);<br>
void_12->setTailCall(false);<br>
AttributeSet void_12_PAL;<br>
void_12->setAttributes(void_12_PAL);<br>
<br>
ReturnInst::Create(mod->getContext(), const_int32_7,
label_entry_10);<br>
<br>
}<br>
<br>
return mod;<br>
}<br>
<br>
The BitCastInst is the key.<br>
<br>
-Rich<br>
</body>
</html>