我正在编写一个应调用其他函数的main函数,但出现此错误。
libc++abi.dylib: Pure virtual function called!
我将函数调用注入主函数的方式是:
Type * returnType = Type::getInt32Ty(TheContext);
std::vector<Type *> argTypes(0, Type::getInt32Ty(TheContext));
FunctionType * functionType = FunctionType::get(returnType, argTypes, false);
Function * function = Function::Create(functionType, Function::ExternalLinkage, "main", TheModule.get());
function->getBasicBlockList().clear();
BasicBlock * BB = BasicBlock::Create(TheContext, "entry", function);
Builder.SetInsertPoint(BB);
for (const auto & call : calls) {
Builder.CreateCall(call.first, call.second, "call");
}
Builder.CreateRet(Builder.getInt32(0));
verifyFunction(*function);
如果我运行此for循环,我会提到错误 但是生成的IR似乎很好,但出于某种原因,它称其为“ calltmp?”而不是“ call”,您知道如何解决此问题吗?
declare i32 @writeln(i32)
define i32 @a() {
entry:
ret i32 3
}
ine i32 @__anon_call() {
entry:
%calltmp = call i32 @a()
%calltmp1 = call i32 @writeln(i32 %calltmp)
ret i32 %calltmp1
entry2: ; No predecessors!
%calltmp3 = call i32 @a()
%calltmp4 = call i32 @writeln(i32 %calltmp3)
ret i32 %calltmp4
}
define i32 @main() {
entry:
%call = call i32 @a()
%call1 = call i32 @writeln(i32 %calltmp)
%call2 = call i32 @a()
%call3 = call i32 @writeln(i32 %calltmp3)
ret i32 0
}