Question

Basically I want to create the data IR for following C code:

extern int myarr1[];
int myarr2 = {(int)&myarr1, 0, 0};

So I created an llvm::GlobalVariable object for myarr1. But llvm asserted out and said it can't be used as an initializer.

Wrong type in array element initializer

Is it possible to do this?

Was it helpful?

Solution

Got the answer:

llvm::Constant *cons = ConstantExpr::getCast(Instruction::PtrToInt, gvar_array_myarr1, IntegerType::get(mod->getContext(), 32));

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top