henry
henry

Reputation: 185

Error when converting Value* to PointerType in llvm pass

I try to instrument load/store instructions in LLVM IR and trace their memory address, therefore I need to insert instrumentation function to record the address of load/store instructions.

I have a type conversion problem when I try to create recordLoad/Store function:

First, I create pointer type, "VoidPtrType"

Type Int64Type = IntegerType::getInt64Ty(M.getContext());
Type* VoidPtrType = PointerType::getUnqual(Int64Type);

Then, I create arguments for instrumented function:

// ldstInst is a load/store instruction
Value* Args[] = {
    ConstantInt::get(Int64Type, uint64_t(lsIDpass->getlsID(inst))),
    ConstantInt::get(VoidPtrType, uint64_t(ldstInst->getPointerOperand())),
    ConstantInt::get(Int64Type, uint64_t(DL->getTypeStoreSize(VTy)))
};

However, when I run my program, I can not pass "ConstantInt::get(VoidPtrType, uint64_t(ldstInst->getPointerOperand()))", the error message is provided below:

Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible type!"

Could anyone provide me any hints?

Thanks, Henry

Upvotes: 1

Views: 1337

Answers (1)

Nikolai
Nikolai

Reputation: 1549

The problem is that VoidPtrType is not of IntegerType (instead, it's of PointerType). I believe that you need to use inttoptr cast to create a constant pointer.

Though, I'm not sure about your design. Do you really want to use pointer to LLVM Operand, which exists only at compile time, in your compiled program?

Upvotes: 1

Related Questions