<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:14pt"><div>Hi,<br>I am trying to insert a function into the LLVM IR. But i get a stack dump exception. My code is as follows.<br><br> <br><br>#include "llvm/Pass.h"
<br>#include "llvm/Function.h"
<br>#include "llvm/Module.h"
<br>#include "llvm/Support/raw_ostream.h"
<br>#include "llvm/ADT/Statistic.h"
<br>#include "llvm/Support/IRBuilder.h"
<br>using namespace llvm;
<br> <br><br>namespace {
<br>  struct FunctionInsert : public ModulePass {
<br>    static char ID;<br>    FunctionInsert() : ModulePass(ID) {}
<br><br>  };
<br>    virtual bool runOnModule(Module &M) {
<br>    
<br><br>     FunctionType* ty=FunctionType::get(Type::getInt32Ty(M.getContext()),false);
<br></div><div id=":77">       Function *func =  cast<Function>(M.<wbr>getOrInsertFunction("func", ty,Type::getInt32Ty(M.<wbr>getContext()),  (Type *)0)); 
<br>      BasicBlock *BB = BasicBlock::Create(M.<wbr>getContext(), "bb1", func);
<br>      IRBuilder<> builder(BB);
<br>       Value *One = builder.getInt32(1);
<br>      Argument *ArgX = func->arg_begin();   
<br>      ArgX->setName("firstarg");    <wbr>        
<br>     Value *Add = builder.CreateAdd(One, ArgX);
<br>     builder.CreateRet(Add);
<br>    return true;
<br>    }
<br>  };
<br>}
<br> <br>char FunctionInsert::ID = 0;
<br>static RegisterPass<FunctionInsert> X("FunctionInsert", "Function Insertion Pass");
<br><br>Most of the above code is from the file examples/HowToUseJIT/<wbr>HowToUseJIT.cpp.<br>Thanks<img src="http://mail.yimg.com/ok/u/assets/img/emoticons/emo1.gif" alt=":) happy"></div></div></body></html>