[LLVMdev] inserting exit function into IR

George Baah georgebaah at gmail.com
Thu Mar 31 12:31:50 PDT 2011


Hi Joshua,
      I have a function foo and I want to insert exit(0) at the end of foo.
The problem is M.getFunction returns null, which is understandable. I am not
sure what to do. Below is the code snippet.

void foo(int argc, char* argv[]) {
  printf("hello world\n");
  exit(0); //***I want to insert this exit
}

My llvm code snippet is

vector<const Type *> params = vector<const Type *>();

params.push_back(Type::getInt32Ty(M.getContext()));

FunctionType *fType =
FunctionType::get(Type::getVoidTy(M.getContext()),  params,
false);

Constant *temp = M.getFunction("exit", fType);

if(!temp){

 errs() << "exit function not in symbol table\n";

 exit(1);

}

Function *f = cast<Function>(temp);


   CallInst *ci = CallInst::Create(...)




On Thu, Mar 31, 2011 at 2:46 PM, Joshua Warner <joshuawarner32 at gmail.com>wrote:

> Hi George,
>
> Could you be a more specific about what you are trying to do, how you are
> trying to do it, and what is failing.  A couple of relevant snippets of code
> would do wonders in helping you.
>
> Thanks,
>
> Joshua
>
> On Wed, Mar 30, 2011 at 3:59 PM, George Baah <georgebaah at gmail.com> wrote:
>
>> Hi Everyone,
>>     I am trying to insert an exit function into my IR.
>> However, I thought I can get access to exit by using
>> Module.getOrInsertFunction or Module.getFunction. However, I am
>> getting a null value returned. I have searched through the llvmdev
>> archives
>> but not found any thing that addresses this question.
>>
>> Any help will be greatly appreciated. Thanks.
>>
>> George
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110331/2c9f1f0f/attachment.html>


More information about the llvm-dev mailing list