Skip to content

Commit 34be80a

Browse files
authored
[mlir-runner] Check entry function does not expect arguments (#136825)
This PR fixes a crash if entry function has inputs. Fixes #136143.
1 parent 18b885f commit 34be80a

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

mlir/lib/ExecutionEngine/JitRunner.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,14 @@ static Error compileAndExecuteVoidFunction(
222222
CompileAndExecuteConfig config, std::unique_ptr<llvm::TargetMachine> tm) {
223223
auto mainFunction = dyn_cast_or_null<LLVM::LLVMFuncOp>(
224224
SymbolTable::lookupSymbolIn(module, entryPoint));
225-
if (!mainFunction || mainFunction.empty())
225+
if (!mainFunction || mainFunction.isExternal())
226226
return makeStringError("entry point not found");
227227

228+
if (cast<LLVM::LLVMFunctionType>(mainFunction.getFunctionType())
229+
.getNumParams() != 0)
230+
return makeStringError(
231+
"JIT can't invoke a main function expecting arguments");
232+
228233
auto resultType = dyn_cast<LLVM::LLVMVoidType>(
229234
mainFunction.getFunctionType().getReturnType());
230235
if (!resultType)
@@ -274,7 +279,8 @@ Error compileAndExecuteSingleReturnFunction(
274279

275280
if (cast<LLVM::LLVMFunctionType>(mainFunction.getFunctionType())
276281
.getNumParams() != 0)
277-
return makeStringError("function inputs not supported");
282+
return makeStringError(
283+
"JIT can't invoke a main function expecting arguments");
278284

279285
if (Error error = checkCompatibleReturnType<Type>(mainFunction))
280286
return error;

mlir/test/mlir-runner/verify-entry-point-result.mlir

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: not mlir-runner %s -e entry_point_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT-VOID
2+
// RUN: not mlir-runner %s -e entry_inputs_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS-VOID
3+
// RUN: not mlir-runner %s -e entry_result_void -entry-point-result=void 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-VOID
4+
// RUN: not mlir-runner %s -e entry_point_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-POINT-I32
5+
// RUN: not mlir-runner %s -e entry_inputs_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-INPUTS-I32
6+
// RUN: not mlir-runner %s -e entry_result_i32 -entry-point-result=i32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-I32
7+
// RUN: not mlir-runner %s -e entry_result_i64 -entry-point-result=i64 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-I64
8+
// RUN: not mlir-runner %s -e entry_result_f32 -entry-point-result=f32 2>&1 | FileCheck %s --check-prefix=CHECK-ENTRY-RESULT-F32
9+
10+
// CHECK-ENTRY-POINT-VOID: Error: entry point not found
11+
llvm.func @entry_point_void() -> ()
12+
13+
// CHECK-ENTRY-INPUTS-VOID: Error: JIT can't invoke a main function expecting arguments
14+
llvm.func @entry_inputs_void(%arg0: i32) {
15+
llvm.return
16+
}
17+
18+
// CHECK-ENTRY-RESULT-VOID: Error: expected void function
19+
llvm.func @entry_result_void() -> (i32) {
20+
%0 = llvm.mlir.constant(0 : index) : i32
21+
llvm.return %0 : i32
22+
}
23+
24+
// CHECK-ENTRY-POINT-I32: Error: entry point not found
25+
llvm.func @entry_point_i32() -> (i32)
26+
27+
// CHECK-ENTRY-INPUTS-I32: Error: JIT can't invoke a main function expecting arguments
28+
llvm.func @entry_inputs_i32(%arg0: i32) {
29+
llvm.return
30+
}
31+
32+
// CHECK-ENTRY-RESULT-I32: Error: only single i32 function result supported
33+
llvm.func @entry_result_i32() -> (i64) {
34+
%0 = llvm.mlir.constant(0 : index) : i64
35+
llvm.return %0 : i64
36+
}
37+
38+
// CHECK-ENTRY-RESULT-I64: Error: only single i64 function result supported
39+
llvm.func @entry_result_i64() -> (i32) {
40+
%0 = llvm.mlir.constant(0 : index) : i32
41+
llvm.return %0 : i32
42+
}
43+
44+
// CHECK-ENTRY-RESULT-F32: Error: only single f32 function result supported
45+
llvm.func @entry_result_f32() -> (i32) {
46+
%0 = llvm.mlir.constant(0 : index) : i32
47+
llvm.return %0 : i32
48+
}

0 commit comments

Comments
 (0)