From dc85a8b29679635fd252744416059100143cb3d8 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 26 Aug 2022 17:33:03 +0200 Subject: [PATCH] Avoid forward declaring the entry point without actually defining it --- src/IRBuilder.cpp | 5 +++++ tests/declare-main.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/IRBuilder.cpp b/src/IRBuilder.cpp index d0df9ec..ceb7b72 100644 --- a/src/IRBuilder.cpp +++ b/src/IRBuilder.cpp @@ -37,6 +37,11 @@ void IRBuilder::create_program(std::shared_ptr program) { Error::throw_error_without_location(format_string("Missing entry point: %s", Arguments::values["entry"])); } + if (module->getFunction(Arguments::values["entry"])->empty()) + { + Error::throw_error_without_location( + format_string("Entry point %s has no body", Arguments::values["entry"])); + } } } diff --git a/tests/declare-main.json b/tests/declare-main.json index 7b86ff5..4781f95 100644 --- a/tests/declare-main.json +++ b/tests/declare-main.json @@ -2,8 +2,8 @@ "file": "declare-main.sp", "compile": { "flags": [], - "exit-code": 0, + "exit-code": 1, "stdout": "", - "stderr": "" + "stderr": "\u001b[1;1m\u001b[31;49merror: \u001b[0;0mEntry point main has no body\n" } } \ No newline at end of file