Got the answer:
llvm::Constant *cons = ConstantExpr::getCast(Instruction::PtrToInt, gvar_array_myarr1, IntegerType::get(mod->getContext(), 32));
Thanks!
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?
Solution
Got the answer:
llvm::Constant *cons = ConstantExpr::getCast(Instruction::PtrToInt, gvar_array_myarr1, IntegerType::get(mod->getContext(), 32));
Thanks!