[llvm-dev] Call printf with new args
    Dávid Bolvanský via llvm-dev 
    llvm-dev at lists.llvm.org
       
    Wed Apr  4 12:38:34 PDT 2018
    
    
  
Hello,
My code: (CallInst *CI, IRBuilder<> &B)
    SmallVector<Value *, 8> args;
    Value *v = B.CreateGlobalString("hi", "str");
    args.push_back(v);
    SmallVector<Type*, 8> params;
    params.push_back(v->getType());
    Module *M = B.GetInsertBlock()->getParent()->getParent();
    FunctionType *printfType = FunctionType::get(B.getInt32Ty(), params,
true);
    Constant* const_printf = M->getOrInsertFunction("printf", printfType);
    Function *F = cast<Function>(const_printf);
    F->dump();
    CallInst * opInst = B.CreateCall(F, args, "call");
It crashes with:
void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*,
llvm::ArrayRef<llvm::Value*>,
llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const
llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i)
== Args[i]->getType()) && "Calling a function with a bad signature!"'
failed.
Any advices how to fix it? Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180404/b0a3dfd1/attachment.html>
    
    
More information about the llvm-dev
mailing list