[llvm-dev] how to convert value to size_t

sangeeta chowdhary via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 16 21:00:37 PDT 2018


Hi,

I am instrumenting load and store and passing memory address to the instrumented function like below - 

 	Type* void_ptr_ty = PointerType::getUnqual(Type::getInt8Ty(M.getContext()));
 	RecordMem = M.getOrInsertFunction("RecordMem", VoidTy, size_ty, void_ptr_ty);

 	bool IsWrite = isa<StoreInst>(*I);
  	Value *Addr = IsWrite
      		? cast<StoreInst>(I)->getPointerOperand()
      		: cast<LoadInst>(I)->getPointerOperand();

 	BitCastInst* bitcast = new BitCastInst(Addr,
           PointerType::getUnqual(Type::getInt8Ty(M.getContext())),
             "", I); 
 
  	ArgsV.push_back(bitcast);
 
  	IRB.CreateCall(RecordMem, ArgsV);

and in function RecordMem, I am type casting void Addr to size_t - 

	extern "C" void RecordMem(THREADID threadid, void * addr) {
  		size_t addr_addr = (size_t)addr;
		…
	}

I don’t want to type cast to size_t in RecordMem. I want to pass it as size_t from llvm pass.

My RecordMem interface now is - 

		extern "C" void RecordMem(THREADID threadid, size_t addr) {}

How can I achieve this? How can I pass the address as size_t?




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180716/08577f8f/attachment.html>


More information about the llvm-dev mailing list