diff --git a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp index 03563006685a..66973ee3ebcf 100644 --- a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp @@ -490,6 +490,9 @@ Function *FunctionAST::codegen() { if (!TheFunction) return nullptr; + if (!TheFunction->empty()) + return (Function *)LogErrorV("Function cannot be redefined."); + // Create a new basic block to start insertion into. BasicBlock *BB = BasicBlock::Create(*TheContext, "entry", TheFunction); Builder->SetInsertPoint(BB);