[LLVMdev] printf decleration

Ryan M. Lefever lefever at crhc.uiuc.edu
Sun Apr 30 22:32:58 PDT 2006


I am writing a pass where I need to make a function deceleration for 
printf.  Below is the code I'm trying to use.

-----
bool MyPass::runOnModule(Module &m) {
   vector<const Type*> args;
   args.push_back(PointerType::get(Type::SByteTy));
   Function* f = m.getOrInsertFunction("printf",
        FunctionType::get(Type::IntTy, args, true));
-----

When I insert a call instruction to printf, I am using the following code:

-----
   /* i an Instruction*, and f is the Function* from above */
   std::vector<Value*> args;
   args.push_back(ConstantArray::get("test"));

   new CallInst(f, args, "", i);
-----

However, when my pass is run with opt it complains:

-----
Call parameter type does not match function signature!
[5 x sbyte] c"test\00"
  sbyte* call int (sbyte*, ...)* %printf( [5 x sbyte] c"test\00" )  ;
<int>:0 [#uses=0]
-----

Does anyone know what the problem is?

Thanks,
Ryan

-- 
Ryan M. Lefever  [217.333.7231]  [http://www.ews.uiuc.edu/~lefever]




More information about the llvm-dev mailing list