How to get the bit representation of some stored value?

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

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)

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.