static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
+ FunctionType *FibFTy = FunctionType::get(Type::getInt32Ty(Context),
+ {Type::getInt32Ty(Context)}, false);
Function *FibF =
- cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context),
- Type::getInt32Ty(Context)));
+ Function::Create(FibFTy, Function::ExternalLinkage, "fib", M);
// Add a basic block to the function.
BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF);