I did M.getOrInsertFunction and called the exit function with .<div><br></div><div><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.54">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
span.s1 {color: #005032}
</style>


<p class="p1"><span class="s1">IRBuilder</span><> builder = IRBuilder<>(...);</p></div><div><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.54">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
span.s1 {color: #005032}
span.s2 {color: #642880}
span.s3 {color: #2a00ff}
span.Apple-tab-span {white-space:pre}
</style>


<p class="p1"><span class="s1">Value</span> *one = <span class="s1">ConstantInt</span>::<span class="s2">get</span>(<span class="s1">Type</span>::<span class="s2">getInt32Ty</span>(M.getContext()),1);</p>
<p class="p1">builder.CreateCall(exitF,one,<span class="s3">"tmp4"</span>);</p><p class="p1"><br></p></div><div><div>"Instruction has a name, but provides a void value!</div><div>  %tmp4 = call void @exit(i32 1)</div>
<div>Broken module found, compilation aborted! "</div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote">On Thu, Mar 31, 2011 at 3:51 PM, Frits van Bommel <span dir="ltr"><<a href="mailto:fvbommel@gmail.com">fvbommel@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Thu, Mar 31, 2011 at 9:31 PM, George Baah <<a href="mailto:georgebaah@gmail.com">georgebaah@gmail.com</a>> wrote:<br>

> Hi Joshua,<br>
>       I have a function foo and I want to insert exit(0) at the end of foo.<br>
> The problem is M.getFunction returns null, which is understandable. I am not<br>
> sure what to do. Below is the code snippet.<br>
> void foo(int argc, char* argv[]) {<br>
>   printf("hello world\n");<br>
>   exit(0); //***I want to insert this exit<br>
> }<br>
> My llvm code snippet is<br>
><br>
> vector<const Type *> params = vector<const Type *>();<br>
<br>
</div>The initialization is unnecessary (but harmless).<br>
<div class="im"><br>
> params.push_back(Type::getInt32Ty(M.getContext()));<br>
><br>
> FunctionType *fType = FunctionType::get(Type::getVoidTy(M.getContext()),<br>
> params, false);<br>
><br>
> Constant *temp = M.getFunction("exit", fType);<br>
<br>
</div>M.getOrInsertFunction("exit", fType);<br>
<div><div></div><div class="h5"><br>
> if(!temp){<br>
><br>
> errs() << "exit function not in symbol table\n";<br>
><br>
> exit(1);<br>
><br>
> }<br>
><br>
> Function *f = cast<Function>(temp);<br>
><br>
> CallInst *ci = CallInst::Create(...)<br>
</div></div></blockquote></div><br></div>