diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp --- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp @@ -131,7 +131,12 @@ // based on `getKernelGlobalVariables()` call. Update this function's name // to: // {spv_module_name}_{function_name} - auto entryPoint = *module.getOps().begin(); + auto entryPoints = module.getOps(); + if (!llvm::hasSingleElement(entryPoints)) { + return module.emitError( + "The module must contain exactly one entry point function"); + } + spirv::EntryPointOp entryPoint = *entryPoints.begin(); StringRef funcName = entryPoint.getFn(); auto funcOp = module.lookupSymbol(entryPoint.getFnAttr()); StringAttr newFuncName = @@ -313,8 +318,12 @@ // Finally, modify the kernel function in SPIR-V modules to avoid symbolic // conflicts. - for (auto spvModule : module.getOps()) - (void)encodeKernelName(spvModule); + for (auto spvModule : module.getOps()) { + if (failed(encodeKernelName(spvModule))) { + signalPassFailure(); + return; + } + } } }; } // namespace diff --git a/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls_fail.mlir b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls_fail.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls_fail.mlir @@ -0,0 +1,7 @@ +// RUN: mlir-opt --lower-host-to-llvm %s -verify-diagnostics + +module { +// expected-error @+1 {{The module must contain exactly one entry point function}} + spirv.module Logical GLSL450 { + } +}