LLVMVerifyFunction:指令不支配所有用途

时间:2015-11-27 00:01:36

标签: c llvm llvm-ir

以下代码段有什么问题?我得到了"指令并没有主导所有用途"在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(),
                                        &params,
                                        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;
}

0 个答案:

没有答案