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

Kostya Serebryany via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 4 10:34:44 PDT 2015


On Fri, Sep 4, 2015 at 9:10 AM, Traian Florin Şerbănuţă <
llvm-dev at lists.llvm.org> wrote:

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


> 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
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150904/72cc3a81/attachment.html>


More information about the llvm-dev mailing list