This was caused because of casting a pointer to an integer.
So, I got the cast opcode and then cast it like following and it worked fine. The process was not killed.
for (auto &v : arg_values) {
argsV.push_back(builder.CreateGlobalStringPtr(v->getName(), ""));
//const DataLayout &DL = M.getDataLayout();
unsigned SourceBitWidth = DL.getTypeSizeInBits(v->getType());
//unsigned SourceBitWidth = cast<IntegerType>(v->getType())->getBitWidth();;
//errs()<<"opcode: "<<CastInst::getCastOpcode(v, false, v->getType(), false)<<"\n";
IntegerType *IntTy = builder.getIntNTy(SourceBitWidth);
//Value *IntResult = builder.CreateBitCast(v, IntTy);
Instruction::CastOps opcode = CastInst::getCastOpcode(v, false, v->getType(), false);
Value *IntResult = builder.CreateCast(opcode, v, Type::getInt32Ty(context));
Value *Int64Result = builder.CreateSExtOrTrunc(IntResult, Type::getInt32Ty(context));
argsV.push_back(Int64Result);
}
However, getCastOpcode does not support array types such as [2 x i32], that’s why I got this error while executing the .ll file.
So, I kept the same for the other values but changed it for pointers like following,
or (auto &v : arg_values) {
argsV.push_back(builder.CreateGlobalStringPtr(v->getName(), ""));
const DataLayout &DL = M.getDataLayout();
unsigned SourceBitWidth = DL.getTypeSizeInBits(v->getType());
//unsigned SourceBitWidth = cast<IntegerType>(v->getType())->getBitWidth();;
IntegerType *IntTy = builder.getIntNTy(SourceBitWidth);
//Value *IntResult = builder.CreateBitCast(v, IntTy);
//Instruction::CastOps opcode = CastInst::getCastOpcode(v, false, IntTy, false);
//Value *IntResult = builder.CreateCast(opcode, v, IntTy);
Value *IntResult;
if(v->getType()->isPointerTy()){
IntResult = builder.CreatePtrToInt(v, IntTy);
}
else{
IntResult = builder.CreateBitCast(v, IntTy);
}
Value *Int32Result = builder.CreateSExtOrTrunc(IntResult, Type::getInt32Ty(context));
argsV.push_back(Int32Result);
//argsV.push_back(v);
}
But now the process is killed, any suggestions.