How to read memory data througn adress of unsigned long

I have a value of long type and like to get the data at the adress in the value:

I have a value of long type and like to get the data at the adress in the value:

#################
unsigned long v = 0xc0008000
Value* addr = ConstantInt::get(getIntegerType(64), v)
####################

Then I try to use LoadInstr to get a load instruction of ir as the following:
############################
Value* data = new LoadInst(addr, "", false, bb);
encounter segmentation fault.
########################

Perhaps you should use a debug build of LLVM so you get an assert
message instead of a segfault. Here you're trying to load from an
integer without first casting it to a pointer, which you do next.

I also try to use IntToPtrInstr to do some transform as the following:
################################
Type const *intptr_type =
cpu->dyncom_engine->exec_engine->getTargetData()->getIntPtrType(_CTX());
Value* ptr = new IntToPtrInst(v, intptr_type, "", bb);
Value* data = new LoadInst(ptr, "", false, bb);
########################################
still encounter segmentation fault

Any person can give me some hints for my case? Thanks in advance. I
have tried a long time with different ways.

Not sure why, but using a debug build would be helpful and using
IRBuilder would help make your code less error-prone.

Reid

getIntPtrType() doesn't return a pointer type, it returns an integer
type that's at least as big as a pointer on the target in question. In
other words: it returns a type that can be used as C's intptr_t.

Micheal, you need to create an actual pointer type based on the type
of value you want to load. For example, to load a 32-bit integer:
  Type* T = Type::getInt32Ty(_CTX())->getPointerTo();
  Value* ptr = new IntToPtrInst(v, T, "", bb);
  Value* data = new LoadInst(ptr, "", false, bb);

I agree that it's better to use IRBuilder though: it makes things
easier (no need to keep passing 'bb', for example) and can do some
automatic early constant folding for you (if you want).
And it definitely helps to compile with assertions enabled so you get
more meaningful errors when you make mistakes.