2016-12-18 9 views
1

関数呼び出しをfoo(idx、mn)にしたLLVMで関数を作成したいと考えています。 fooの関数プロトタイプはvoid foo(unsigned char, const char*)です。llvm createCall不正なシグネチャを持つ関数を呼び出す

lib/IR/Instructions.cpp:245: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef, llvm::ArrayRef >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.

fooの最初の引数は型の不一致を持っているようだ:

// adapter Function with only a function call foo(idx, mn) 
llvm::Function* createCallFun(llvm::Module* M, llvm::Function* exit_f) { 

    llvm::LLVMContext& Ctx = M->getContext(); 
    llvm::Function* foo_f = foo_prototype(Ctx, M); 

    llvm::Constant* c = M->getOrInsertFunction("__call_fun", FunctionType::getVoidTy(Ctx), llvm::Type::getInt32Ty(Ctx), llvm::Type::getInt32Ty(Ctx), NULL); 
    llvm::Function* call_fun_f = llvm::cast<llvm::Function>(c); 

    llvm::BasicBlock* entry = llvm::BasicBlock::Create(llvm::getGlobalContext(), "entry", call_fun_f); 
    llvm::IRBuilder<> builder(entry); 

    llvm::Function::arg_iterator args = call_fun_f->arg_begin(); 
    llvm::Value* idx = &*args++; 
    idx->setName("idx"); 
    llvm::Value* mn = &*args++; 
    mn->setName("mn"); 
    llvm::Value* greater = builder.CreateICmpSGE(idx, mn, "tmp"); 

    std::vector<llvm::Value*> fun_args; 
    fun_args.push_back(greater); 
    fun_args.push_back(err_msg); 
    builder.CreateCall(foo_f, fun_args); 

    return call_fun_f; 
} 

は、その後、私はこのエラーを得ました。値 greaterunsigned charタイプにキャストするにはどうすればよいですか?

答えて

0

キャストgreaterでこのエラーを修正しました。CreateZExtです。

llvm::Value *castuchar = 
    builder.CreateZExt(greater, llvm::Type::getInt8Ty(Ctx), "tmp1"); 
関連する問題