[LLVMdev] How to const char* Value for function argument

James Molloy James.Molloy at arm.com
Thu Sep 22 03:15:53 PDT 2011

Hi Dimitry,

This makes sense if you think about it from the perspective that the string you want passing must be passed at runtime, and so can't use a const char * from compile time.

You need to make the string visible in the compiled image, and use that as the argument. A string is an array of 8-bit integers, so you need to create a ConstantArray.

Value *v = ConstantArray::get(Context, callee->getName(), /*AddNull=*/true);



-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Dmitry N. Mikushin
Sent: 22 September 2011 11:06
To: LLVM-Dev
Subject: [LLVMdev] How to const char* Value for function argument


I'm trying to replace function call with call to
wrapper(function_name, num_args, ...), where varargs hold args of
original call.

        Function* launch = Function::Create(
                TypeBuilder<int(const char*, int, ...), false>::get(context),
                GlobalValue::ExternalLinkage, "kernelgen_launch_", m2);

                                        CallInst* call = dyn_cast<CallInst>(cast<Value>(I));
                                        if (!call) continue;
                                        Function* callee = call->getCalledFunction();
                                        if (!callee && !callee->isDeclaration()) continue;
                                        if (callee->getName() != func2.getName()) continue;

                                        SmallVector<Value*, 16> callargs(call->op_begin(), call->op_end());
                                        callargs.insert(callargs.begin(), callee->getName());
                                        CallInst* newcall = CallInst::Create(launch, callargs, "", call);

                                        found = true;

The line callargs.insert(callargs.begin(), callee->getName()); is
invalid: instead of StringRef I need to supply a Value* for the second
argument. How to construct value for const char* ?

- D.
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.

More information about the llvm-dev mailing list