[llvm] [llubi] Error if main is not a definition (PR #226475)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 06:01:21 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/226475

Currently this crashes. Ran into this while using llubi with llvm-reduce.

>From a88da450f1eca50e81d74f69ed5ce6995641e3c5 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 25 Sep 2026 14:59:40 +0200
Subject: [PATCH] [llubi] Error if main is not a definition

Currently this crashes. Ran into this while using llubi with
llvm-reduce.
---
 llvm/test/tools/llubi/main_declaration.ll | 5 +++++
 llvm/tools/llubi/llubi.cpp                | 5 +++++
 2 files changed, 10 insertions(+)
 create mode 100644 llvm/test/tools/llubi/main_declaration.ll

diff --git a/llvm/test/tools/llubi/main_declaration.ll b/llvm/test/tools/llubi/main_declaration.ll
new file mode 100644
index 00000000000000..68d5c430f87693
--- /dev/null
+++ b/llvm/test/tools/llubi/main_declaration.ll
@@ -0,0 +1,5 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
+; RUN: not llubi --verbose < %s 2>&1 | FileCheck %s
+
+declare i32 @main()
+; CHECK: error: 'main' must be definition.
diff --git a/llvm/tools/llubi/llubi.cpp b/llvm/tools/llubi/llubi.cpp
index eb45a1a5b84b56..659b0926411c01 100644
--- a/llvm/tools/llubi/llubi.cpp
+++ b/llvm/tools/llubi/llubi.cpp
@@ -277,6 +277,11 @@ int main(int argc, char **argv) {
                        << "\' function not found in module.\n";
     return 1;
   }
+  if (EntryFn->isDeclaration()) {
+    WithColor::error() << '\'' << EntryFunc
+                       << "\' must be definition.\n";
+    return 1;
+  }
   TargetLibraryInfo TLI(Ctx.getTLIImpl());
   Type *IntTy = IntegerType::get(Ctx.getContext(), TLI.getIntSize());
   Type *PtrTy = PointerType::getUnqual(Ctx.getContext());



More information about the llvm-commits mailing list