[LLVMdev] How do I insert a printf call in the IR?

Nick Lewycky nicholas at mxc.ca
Sat Nov 15 16:49:09 PST 2008

Shah, Mrunal J wrote:
> Once I have the function
> to make a call to this function I use
> CallInst::Create(myPrint, args.begin(), args.end(),"", B);
> But I am not being able to pass a string into the argument vector.
> should I define args as
> std::vector<const Type*> args;
> or
> std::vector<const PointerType*> args;
> or 
> std::vector<Value*> args;
> and how do I convert a constant string to either of these types, so that I can push it on the args list.

You need to put the string constant into a GlobalVariable (which is a 

This is a bit tricky if you're using the direct API. I suggest using 
"llc -march=cpp" on a program that does printf("Hello world!");

Using IRBuilder is easier. Starting with LLVM 2.4, there's a 
CreateGlobalString function that takes a const char *String and returns 
a Value*.


> Thanks!
> Mrunal
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list