我正在尝试使用以下代码创建新的Store
指令:
AllocaInst* newTemp = new AllocaInst(llvm::Type::getInt32Ty(Context), 0, 4,tVname);
bb->getInstList().insert(original, newTemp);
Value* dest = inst->getOperand(1);
StoreInst *strTwo = new StoreInst(newTemp, dest,0,4); //newTemp creates error
bb->getInstList().insert(bfrInst, strTwo);
当我运行代码时,它会抛出异常:
void llvm::StoreInst::AssertOK(): Assertion getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
我应该如何修改代码以使其无错误?
答案 0 :(得分:1)
根据http://llvm.org/docs/doxygen/html/classllvm_1_1StoreInst.html
StoreInst获取第一个参数值,第二个作为指针。 好像你正在反向进行
StoreInst *strTwo = new StoreInst(newTemp, dest,0,4); //newTemp creates error
如果您尝试将dest存储到newtemp alloca指针,请尝试:
StoreInst *strTwo = new StoreInst(dest, newtemp,0,4); //newTemp creates error