[PATCH] D154352: [mlir-cpu-runner] Check entry function is void

Cullen Rhodes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 3 07:56:49 PDT 2023


c-rhodes created this revision.
c-rhodes added a reviewer: ftynse.
c-rhodes added a project: MLIR.
Herald added subscribers: bviyer, Moerafaat, zero9178, bzcheeseman, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: All.
c-rhodes requested review of this revision.
Herald added subscribers: stephenneuendorffer, nicolasvasilache.

Currently crashes if function isn't void when specifiying
'-entry-point-result=void'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154352

Files:
  mlir/lib/ExecutionEngine/JitRunner.cpp
  mlir/test/mlir-cpu-runner/verify-entry-point-result.mlir


Index: mlir/test/mlir-cpu-runner/verify-entry-point-result.mlir
===================================================================
--- /dev/null
+++ mlir/test/mlir-cpu-runner/verify-entry-point-result.mlir
@@ -0,0 +1,7 @@
+// RUN: not mlir-cpu-runner %s entry -entry-point-result=void 2>&1 | FileCheck %s
+
+// CHECK: Error: expected void function
+llvm.func @entry() -> (i32) {
+  %0 = llvm.mlir.constant(0 : index) : i32
+  llvm.return %0 : i32
+}
Index: mlir/lib/ExecutionEngine/JitRunner.cpp
===================================================================
--- mlir/lib/ExecutionEngine/JitRunner.cpp
+++ mlir/lib/ExecutionEngine/JitRunner.cpp
@@ -224,6 +224,12 @@
       SymbolTable::lookupSymbolIn(module, entryPoint));
   if (!mainFunction || mainFunction.empty())
     return makeStringError("entry point not found");
+
+  auto resultType = dyn_cast<LLVM::LLVMVoidType>(
+      mainFunction.getFunctionType().getReturnType());
+  if (!resultType)
+    return makeStringError("expected void function");
+
   void *empty = nullptr;
   return compileAndExecute(options, module, entryPoint, std::move(config),
                            &empty, std::move(tm));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154352.536776.patch
Type: text/x-patch
Size: 1169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230703/725f18cc/attachment.bin>


More information about the llvm-commits mailing list