<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 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>