以下代码段有什么问题?我得到了"指令并没有主导所有用途"在LLVMVerifyFunction
:
#include <stdio.h>
#include <llvm-c/Core.h>
#include <llvm-c/Analysis.h>
int main() {
LLVMModuleRef module = LLVMModuleCreateWithName("test");
LLVMBuilderRef builder = LLVMCreateBuilder();
LLVMTypeRef params = LLVMDoubleType();
LLVMTypeRef type = LLVMFunctionType(
LLVMDoubleType(),
¶ms,
1,
0);
LLVMValueRef function = LLVMAddFunction(module, "foo", type);
LLVMSetLinkage(function, LLVMExternalLinkage);
LLVMValueRef param = LLVMGetParam(function, 0);
LLVMSetValueName(param, "a");
LLVMDumpValue(function);
LLVMValueRef one = LLVMConstReal(LLVMDoubleType(), 1);
LLVMValueRef instr = LLVMBuildFAdd(builder, param, one, "addtmp");
LLVMBasicBlockRef block = LLVMAppendBasicBlock(function, "entry");
LLVMPositionBuilderAtEnd(builder, block);
LLVMBuildRet(builder, instr);
// Verify function.
if (LLVMVerifyFunction(function, LLVMPrintMessageAction) == 1) {
LLVMDeleteFunction(function);
printf("bad");
}
LLVMDisposeBuilder(builder);
LLVMDisposeModule(module);
return 0;
}