Oh I see what you mean but I don't think that is the value that I want. <div>In the code, I know that </div><div><br></div><div>%N = load i32* %k, align 4</div><div><meta charset="utf-8">%p = getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N</div>
<div><br></div><div>So I analyze the GEP and know that %N is a pointer to an int32, which is the array index.</div><div>I want to get that index so I can insert a check to see if it violates the array bounds.</div><div>So the final code (in pseudocode) will look like, </div>
<div><br></div><div><meta charset="utf-8">%N = load i32* %k, align 4</div><div>if( 0 <= %N < array-size){</div><div> %p = getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N</div><div> ...</div><div>
}else{</div><div> throw an exception.</div><div>}</div><meta charset="utf-8"><div><br></div><div><br><div class="gmail_quote">On Mon, Mar 28, 2011 at 3:25 PM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi George,<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  For this example,<br>
   getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N<br>
I am trying to retrieve %N and instrument the program to see if the value<br>
pointed to by  %N exceeds the array bound (10). I assume that<br>
%N will be associated with a load instruction. I have searched through<br>
all the tutorials etc. and still have no clue as to how to do this, that is,<br>
get the value and then instrument the code.<br>
</blockquote>
<br></div>
if<br>
  %p = getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N<br>
then you need an instruction<br>
  %v = load %p<br>
to get the value %v pointed to by %p.<br>
<br>
Ciao, Duncan.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
George<br>
<br>
On Mon, Mar 28, 2011 at 4:32 AM, Duncan Sands <<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a><br></div><div class="im">
<mailto:<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>>> wrote:<br>
<br>
    Hi George,<br>
<br>
     >    I am trying to get the first index into this two-dimensional array,<br>
    that is *5.*<br>
<br>
    not sure what you mean, but if you think of your array as being a 10 x 20 matrix<br>
    then to get a pointer to element M,N you would do:<br>
       getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N<br>
<br>
     ><br>
     > %4 = getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 *5*<br>
     > *<br>
     > *<br>
     > I can iterate over the GEP and get the types of the operands but not the<br>
    values.<br>
     ><br>
     > How do I get the value (5)?<br>
<br>
    getelementptr only does pointer arithmetic, i.e. using it you can get a pointer<br>
    to an array element.  But to get the element itself you need to use a load<br>
    instruction to load the value pointed to by the pointer.<br>
<br>
    Ciao, Duncan.<br>
    _______________________________________________<br>
    LLVM Developers mailing list<br></div>
    <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<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><div class="im">
<br>
    <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
</div></blockquote>
<br>
</blockquote></div><br></div>