[llvm-dev] How to get the bit representation of some stored value?

Traian Florin Şerbănuţă via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 4 09:10:33 PDT 2015


Hello,

I'm writing a pass to instrument some code, and I cannot get past something.

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

Is is possible to achieve something like this?
I tried several of the casting creation methods, but I found none working.

I have this code (from ThreadSanitizer)

Value *Addr = cast<StoreInst>(I)->getPointerOperand()

StoredValue = cast<StoreInst>(I)->getValueOperand();

Type *OrigTy = cast<PointerType>(Addr->getType())->getElementType();
const uint32_t TypeSize = DL.getTypeStoreSizeInBits(OrigTy);

and I've tried things like

IRB.CreateIntCast(StoredValue, IRB.getIntNTy(TypeSize), false)

or even attempting to first cast it through a pointer type

IRB.CreateIntCast(IRB.CreatePointerCast(StoredValue,
IRB.getInt8PtrTy()), IRB.getIntNTy(TypeSize), false)


but nothing seem to work (mainly assertions failing)
Could you please point me into the right direction?

Thank you,
Traian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150904/bc6e30ac/attachment.html>


More information about the llvm-dev mailing list