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

Amila Senadheera via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 00:45:44 PST 2023


https://github.com/Amila-Rukshan created https://github.com/llvm/llvm-project/pull/76322

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

>From 41efb912cb7b1cb533ccaf519cccc513b1a76edc Mon Sep 17 00:00:00 2001
From: amila <amila.15 at cse.mrt.ac.lk>
Date: Sun, 24 Dec 2023 13:56:18 +0530
Subject: [PATCH] kaleidoscope tutorial: add missing check in the
 FunctionAST::codegen in chapter 3

Signed-off-by: amila <amila.15 at cse.mrt.ac.lk>
---
 llvm/examples/Kaleidoscope/Chapter3/toy.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/examples/Kaleidoscope/Chapter3/toy.cpp b/llvm/examples/Kaleidoscope/Chapter3/toy.cpp
index 03563006685add..d7539143df3fce 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