<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><span>Hi again,</span></div><div><br><span></span></div><div><span>Thank you, your suggestion worked well. I was looking for a pointer to void actually. But it seems that I do not get the memory address when passing the value of the GEP instruction. </span></div><div><br><span></span></div><div><span>For instance, when I print the address accessed by the second operand of the store instruction<br></span></div><div><br></div><div><span style="font-style: italic;">store %struct.linked* %tmp23.reload8, %struct.linked** %curr.037.reg2mem</span></div><div>I obtain a memory address of the form<br><span></span></div><div style="font-style: italic;"><span>7fff29c28ac8</span></div><div><br></div><div>But when I try to get the address stored in the GEP<br><span></span></div><div><span><span style="font-style: italic;">%tmp18 = getelementptr
 inbounds %struct.linked* %curr.025.reload, i64 0, i32 0</span><br></span></div><div><span>I obtain<br></span></div><div><span><span style="font-style: italic;">2084a10</span></span></div><div><br><span></span></div><div><span>which is not the memory location I expect. Is this the computed memory location, or I did not access it correctly?</span></div><div><br><span></span></div><div><span>Thank you.</span></div><div><br><span></span></div><div><span>Alexandra</span></div><div><br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> John Criswell <criswell@illinois.edu><br><b><span style="font-weight: bold;">To:</span></b> Jimborean Alexandra <xinfinity_a@yahoo.com><br><b><span style="font-weight: bold;">Cc:</span></b>
 llvmdev@cs.uiuc.edu<br><b><span style="font-weight: bold;">Sent:</span></b> Wednesday, July 20, 2011 5:08 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [LLVMdev] print the memory address computed by getelementptr<br></font><br><div id="yiv1927608977">
  

    
  On 7/20/11 10:02 AM, Jimborean Alexandra wrote:
    <blockquote type="cite">
      
      <style type="text/css"><!--#yiv1927608977 DIV {margin:0px;}--></style>
      <div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
        <div>Hi,<br>
          <br>
          I want to print the memory locations computed by
          getelementptr. As I understood, getelementptr does not access
          the memory, but it contains the address it computes. I want to
          print these addresses at runtime (or process them).  So, I try
          to build a function that takes as argument a pointer and
          prints its value. And to call this function, by sending the
          gep instruction as a parameter. <br>
        </div>
      </div>
    </blockquote>
    <br>
    All you really need to do here is to cast the result of the
    getelementptr value to the type of the parameter of your function. 
    In this case, you need to insert a ptrtoint instruction that takes
    the GEP and casts it to an i64.<br>
    <br>
    That said, instead of casting the GEP to an i64, it would be better
    if your run-time function took a void *.  In LLVM IR, a pointer to
    an i8 is a void *, and so you could insert a bitcast of the GEP to
    an i8 * instead of casting it to an i64.  That way, you don't have
    to worry about the pointer size if you start using your code on both
    32-bit and 64-bit targets.<br>
    <br>
    -- John T.<br>
    <br>
    <blockquote type="cite">
      <div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);">
        <div><br>
          Surely, I obtain an error for a type mismatch. Can I declare
          the function as taking an int64 as parameter and then
          (somehow) sending the value computed by getelementptr?<br>
          <br>
          declare void @myFunction ( i64 )<br>
          <br>
          <br>
          %tmp22 = getelementptr inbounds %struct.linked* %tmp21, i32 0,
          i32 1<br>
          <br>
          %tmp = convert_tmp22_to_i64_to_get_the_value_of_the_pointer<br>
          <br>
          call void @myFunction(i64 %tmp)<br>
          <br>
          <br>
          Or could you suggest a better method to get the value computed
          by getelementptr ?<br>
          <br>
          Thanks,<br>
          Alexandra<br>
        </div>
      </div>
      <br>
      <fieldset class="yiv1927608977mimeAttachmentHeader"></fieldset>
      <br>
      <pre>_______________________________________________
LLVM Developers mailing list
<a rel="nofollow" class="yiv1927608977moz-txt-link-abbreviated" ymailto="mailto:LLVMdev@cs.uiuc.edu" target="_blank" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a rel="nofollow" class="yiv1927608977moz-txt-link-freetext" target="_blank" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a rel="nofollow" class="yiv1927608977moz-txt-link-freetext" target="_blank" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  
</div><br><br></div></div></div></body></html>