[llvm] ce6303f - [lli] Fix crash on empty entry-function

Cullen Rhodes via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 02:36:06 PDT 2023


Author: Cullen Rhodes
Date: 2023-07-31T09:29:54Z
New Revision: ce6303f0e6358b9f3121bafab6b20e52ab9a8408

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

LOG: [lli] Fix crash on empty entry-function

Empty entry-function triggers the following assertion:

  llvm/lib/IR/Mangler.cpp:38: void getNameWithPrefixImpl(llvm::raw_ostream
  &, const llvm::Twine &, (anonymous namespace)::ManglerPrefixTy, const
  llvm::DataLayout &, char):

  Assertion `!Name.empty() && "getNameWithPrefix requires non-empty name"' failed.

Throw an error if entry-function is empty.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D156516

Added: 
    llvm/test/ExecutionEngine/Orc/empty-entry-function.ll

Modified: 
    llvm/tools/lli/lli.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/ExecutionEngine/Orc/empty-entry-function.ll b/llvm/test/ExecutionEngine/Orc/empty-entry-function.ll
new file mode 100644
index 00000000000000..2785a2eb8a4654
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/empty-entry-function.ll
@@ -0,0 +1,4 @@
+; RUN: not lli --entry-function= %s 2>&1 | FileCheck %s
+;
+; Test empty --entry-function yields an error.
+; CHECK: error: --entry-function name cannot be empty

diff  --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 3b5250d56707f9..7698b551ac178d 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -446,6 +446,12 @@ int main(int argc, char **argv, char * const *envp) {
 
   ExitOnErr(loadDylibs());
 
+  if (EntryFunc.empty()) {
+    WithColor::error(errs(), argv[0])
+        << "--entry-function name cannot be empty\n";
+    exit(1);
+  }
+
   if (UseJITKind == JITKind::MCJIT)
     disallowOrcOptions();
   else


        


More information about the llvm-commits mailing list