<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 4, 2015 at 9:10 AM, Traian Florin Şerbănuţă <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=llvm-dev@lists.llvm.org&cc=&bcc=&su=&body=','_blank');return false;">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px">Hello,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm writing a pass to instrument some code, and I cannot get past something.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Basically, I would like to instrument all load and store operations in a program and have their address and value passed to a handler function which takes as argument the address and an integer containing the bit representation of the stored/loaded value (I know the value fits into an integer type, although the value itself might not be of integer type).</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Is is possible to achieve something like this?</div><div style="font-size:12.8px">I tried several of the casting creation methods, but I found none working.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I have this code (from ThreadSanitizer)</div><div style="font-size:12.8px"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'"><span style="color:rgb(0,128,128)">Value </span>*Addr = cast<<span style="color:rgb(0,128,128)">StoreInst</span>>(I)->getPointerOperand()</pre></div><div style="font-size:12.8px"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'"><pre style="white-space:pre-wrap;font-family:'DejaVu Sans Mono'">StoredValue = cast<<span style="color:rgb(0,128,128)">StoreInst</span>>(I)->getValueOperand();</pre></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'"><span style="color:rgb(0,128,128)">Type </span>*OrigTy = cast<<span style="color:rgb(0,128,128)">PointerType</span>>(Addr->getType())->getElementType();<br><span style="color:rgb(0,0,128);font-weight:bold">const </span><span style="color:rgb(55,31,128)">uint32_t </span>TypeSize = DL.getTypeStoreSizeInBits(OrigTy);<br></pre></div><div style="font-size:12.8px">and I've tried things like <br></div><div style="font-size:12.8px"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'"><pre style="white-space:pre-wrap;font-family:'DejaVu Sans Mono'">IRB.CreateIntCast(StoredValue, IRB.getIntNTy(TypeSize), <span style="color:rgb(0,0,128);font-weight:bold">false</span>)</pre></pre></div></div></blockquote><div><br></div><div>I'd suggest you to print the values that you create just before the assertion fires -- it will give you a clue why the assertion in unhappy. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'"><pre style="white-space:pre-wrap;font-family:'DejaVu Sans Mono'">or even attempting to first cast it through a pointer type</pre></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'DejaVu Sans Mono'">IRB.CreateIntCast(IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy()), IRB.getIntNTy(TypeSize), <span style="color:rgb(0,0,128);font-weight:bold">false</span>)</pre></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">but nothing seem to work (mainly assertions failing)</div><div style="font-size:12.8px">Could you please point me into the right direction?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thank you,</div><div style="font-size:12.8px">Traian</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=llvm-dev@lists.llvm.org&cc=&bcc=&su=&body=','_blank');return false;">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>