<div dir="ltr">Hi Richard,<div><br></div><div style>First of all, thank you so much for your reply ;)</div><div class="gmail_extra"><div><a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div>
<br><br><div class="gmail_quote">On Tue, May 14, 2013 at 3:36 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On Tue, May 14, 2013 at 11:42 AM, Cristianno Martins <span dir="ltr"><<a href="mailto:cristiannomartins@gmail.com" target="_blank">cristiannomartins@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote">
<div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Hello there,<div><br></div><div>I'm trying to use a simple implementation of a queue (my own implementation of it, actually), and I'm trying to use the functions defined on my queue class inside some llvm-ir code. Unfortunately, the names of the functions are being messed up, then I created some function wrappers just to avoid having to deal with the C++ weird function renaming.</div>
</div></blockquote><div><br></div></div><div>FYI, this "weird function renaming" is traditionally called "name mangling" :)</div></div></blockquote><div style>Thanks for the info, man =) </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="gmail_quote"><div><br></div><div>What frontend are you using? Clang or g++ w/dragonegg or something else?</div></div></blockquote><div><br></div><div style>I'm currently using clang++ 3.4 (directly from its git repo). </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_quote"><div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>So, to easily wrapper the class, I wrote a queue_wrapper.h library, which, basically, has the following code (where Q is a reference to my queue, and the channel is not really important):</div>
</div></blockquote><div><br></div></div><div>The problem is probably in the definition of your queue itself. The code below generates completely reasonable output for me, with...</div><div><br></div><div>struct q {</div>
<div> void addElement(int, char);</div>
<div> char removeElement(int);</div><div> void addPtrElement(int, void*);</div><div> void *removePtrElement(int);</div><div>} *Q;</div></div></blockquote><div><br></div><div style>I just thought it was a little strange that the same code could generate the correct LLVMIR if I've written the wrappers using templates, but only a call to llvm.trap (and only for a subset of the functions) if I use defines =/</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_quote"><div><div class="h5">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p><b><font face="courier new, monospace">extern<span> </span><span>"C"</span><span> {</span> </font></b></p>
</div><div><p><b><font face="courier new, monospace">#ifdef INT_TYPE</font></b></p></div><div><p><b><font face="courier new, monospace"><span> </span>void<span> </span>__attribute__<span>((noinline))</span></font></b></p>
</div><div><p><b><font face="courier new, monospace"> <span>TYPED_NAME</span>(produceValue)(<span>int</span> channel, <span>TYPE</span> elem)</font></b></p></div><div>
<p><b><font face="courier new, monospace"> {Q-><span>addElement</span> (channel, (<span>long</span>)elem);}</font></b></p></div><div><p><b><font face="courier new, monospace"><br>
</font></b></p></div><div><p><b><font face="courier new, monospace"> <span>TYPE</span> <span>__attribute__</span>((noinline))</font></b></p></div><div><p><b><font face="courier new, monospace"> <span>TYPED_NAME</span>(consumeValue)(<span>int</span> channel)</font></b></p>
</div><div><p><b><font face="courier new, monospace"> {<span>return</span> (<span>TYPE</span>) Q-><span>removeElement</span> (channel);}</font></b></p></div><div>
<p>
<b><font face="courier new, monospace">#endif</font></b></p></div><div><p><b><font face="courier new, monospace"><br></font></b></p></div><div><p><b><font face="courier new, monospace"><span> </span>void<span> </span>__attribute__<span>((noinline))</span></font></b></p>
</div><div><p><b><font face="courier new, monospace"> <span>TYPED_NAME</span>(producePtrValue)(<span>int</span> channel, <span>TYPE</span>* elem)</font></b></p></div><div>
<p><b><font face="courier new, monospace"> {Q-><span>addPtrElement</span> (channel, (<span>void</span>*)elem);}</font></b></p></div><div><p><b><font face="courier new, monospace"><br>
</font></b></p></div><div><p><b><font face="courier new, monospace"> <span>TYPE</span>* <span>__attribute__</span>((noinline))</font></b></p></div><div><p><b><font face="courier new, monospace"> <span>TYPED_NAME</span>(consumePtrValue)(<span>int</span> channel)</font></b></p>
</div><div><p><b><font face="courier new, monospace"> {<span>return</span> (<span>TYPE</span>*) Q-><span>removePtrElement</span> (channel);}</font></b></p></div><div>
<p><b><font face="courier new, monospace"> </font></b></p></div><div><p><b><font face="courier new, monospace">#ifdef FP_TYPE</font></b></p></div><div><p><b><font face="courier new, monospace"><span> </span>void<span> </span>__attribute__<span>((noinline))</span></font></b></p>
</div><div><p><b><font face="courier new, monospace"> TYPED_NAME(produceFPValue)(<span>int</span> channel, TYPE elem)</font></b></p></div><div><p><b><font face="courier new, monospace"> {Q->addFPElement (channel, (<span>double</span>)elem);}</font></b></p>
</div><div><p><b><font face="courier new, monospace"><br></font></b></p></div><div><p><b><font face="courier new, monospace"> TYPE <span>__attribute__</span>((noinline))</font></b></p>
</div><div><p><b><font face="courier new, monospace"> TYPED_NAME(consumeFPValue)(<span>int</span> channel)</font></b></p></div><div><p><b><font face="courier new, monospace"> {<span>return</span> (TYPE) Q->removeFPElement (channel);}</font></b></p>
</div><div><p><b><font face="courier new, monospace">#endif</font></b></p></div><div><p><b><font face="courier new, monospace">}</font></b></p></div></blockquote><div>
<div><br></div><div>In order to define a set of functions for a type, I can simply insert the following lines on my original library:</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><p><font face="courier new, monospace"><b>#define INT_TYPE</b></font></p></div></div><div><div><p><font face="courier new, monospace"><b>#define TYPE char</b></font></p>
</div></div><div><div><p><font face="courier new, monospace"><b>#define TYPED_NAME(x) i8_##x</b></font></p></div></div><div><div><p><font face="courier new, monospace"><b><span>#include </span>"queue_wrappers.h"</b></font></p>
</div></div><div><div><p><font face="courier new, monospace"><b>#undef TYPE</b></font></p></div></div><div><div><p><font face="courier new, monospace"><b>#undef TYPED_NAME</b></font></p>
</div></div><div><div><p><font face="courier new, monospace"><b>#undef INT_TYPE</b></font></p></div></div></blockquote><div><div>
<p>And, for this example, the functions i8_produceValue, i8_consumeValue, i8_producePtrValue and i8_consumePtrValue should be defined.</p><p>Well, the problem is that all those functions are being defined, indeed, but every function inside the #ifdef INT_TYPE's preprocessor flag has only a call to llvm.trap() function inside its body =/</p>
</div></div></div></blockquote></div></div><div>One possibility is that you have a function which returns non-void but is missing a 'return' statement. Are you getting any -Wreturn-type warnings? Do you see the call to llvm.trap if you build with no optimizations? If not, can you provide the IR for that?</div>
</div></blockquote><div><br></div><div style>I'm using -O4 as the optimization level for this code. Curiously, I could generate a bc file from my queue.h library (simply creating a queue.cpp file with nothing more than including its respective header file) and the result was a bc file with all the correct function bodies (none of them was referring to llvm.trap). So, for now, I think I'll be using this bc file as my starting point =)</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"><div dir="ltr"><div><div>
<p>And this is only happening to the functions (*)_consumeValue and (*)_produceValue: all the other functions [(*)_consumePtrValue, (*)_producePtrValue, (*)_consumeFPValue and (*)_produceFPValue] has their bodies correctly defined on the resultant bc file.</p>
<p>Since the only difference between their implementation on the queue is the type defined inside the queue (long for integer types, void* for pointers and double for floating point numbers), does anyone have any ideia why I am having this issue with integers?</p>
<p><br></p><p>PS: I tried to implement the integer type functions using C++ templates, and it was as I expected: the functions for integer types were created with their correct set of instructions inside. However, when using templates, the names of the functions are being messed up (which was the issue I was trying to avoid in the first place).</p>
<p>Thanks in advance,</p><p><br>--</p>Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br>
<a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div>
</div></div>
<br></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br>
</blockquote></div><br>--<br>Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br></div></div>