[llvm] 56fe909 - kaleidoscope: add missing check in the FunctionAST::codegen (#76322)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 03:59:39 PDT 2026


Author: Amila Senadheera
Date: 2026-03-09T16:29:35+05:30
New Revision: 56fe9097fc83106db2ebfaade93e41a6aefda425

URL: https://github.com/llvm/llvm-project/commit/56fe9097fc83106db2ebfaade93e41a6aefda425
DIFF: https://github.com/llvm/llvm-project/commit/56fe9097fc83106db2ebfaade93e41a6aefda425.diff

LOG: kaleidoscope: add missing check in the FunctionAST::codegen  (#76322)

kaleidoscope chapter 03 explanation has this function redefine check,
but it was missing in the code sample.

Signed-off-by: amila <amila.15 at cse.mrt.ac.lk>

Added: 
    

Modified: 
    llvm/examples/Kaleidoscope/Chapter3/toy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp
index 03563006685ad..66973ee3ebcfa 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);


        


More information about the llvm-commits mailing list