[mlir][spirv] Fix OOB error in TestModuleCombiner
authorJakub Kuderski <kubak@google.com>
Mon, 24 Apr 2023 17:56:21 +0000 (13:56 -0400)
committerJakub Kuderski <kubak@google.com>
Mon, 24 Apr 2023 17:56:22 +0000 (13:56 -0400)
Also fix a typo in the surrounding code.

Fixes: https://github.com/llvm/llvm-project/issues/62318
Reviewed By: qedawkins

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

mlir/lib/Dialect/SPIRV/Linking/ModuleCombiner/ModuleCombiner.cpp
mlir/test/Dialect/SPIRV/Linking/ModuleCombiner/basic.mlir
mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp

index 3083bb8d8ce6966ad9519fdfcc27122aaf31684a..1f708c2ae37adaedb53225105df86d95ec1f07f0 100644 (file)
@@ -28,7 +28,7 @@ using namespace mlir;
 
 static constexpr unsigned maxFreeID = 1 << 20;
 
-/// Returns an unsed symbol in `module` for `oldSymbolName` by trying numeric
+/// Returns an unused symbol in `module` for `oldSymbolName` by trying numeric
 /// suffix in `lastUsedID`.
 static StringAttr renameSymbol(StringRef oldSymName, unsigned &lastUsedID,
                                spirv::ModuleOp module) {
index f9d46656358c0777d38a80a9654569ae54f752d3..4aed260420ae7e19eecf659a9077739ea95bdd60 100644 (file)
@@ -77,3 +77,11 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_storag
 }
 }
 
+// -----
+
+// No spir-v modules to combine.
+module {
+  func.func @foo(%arg0: i32) -> i32 {
+    return %arg0 : i32
+  }
+}
index 56a2d1d3fdc412645485479a6c785ca827baa9bd..3f5f094ed3afcdaa7d5960e0a02e3685fcd1dc8f 100644 (file)
@@ -34,6 +34,8 @@ public:
 
 void TestModuleCombinerPass::runOnOperation() {
   auto modules = llvm::to_vector<4>(getOperation().getOps<spirv::ModuleOp>());
+  if (modules.empty())
+    return;
 
   OpBuilder combinedModuleBuilder(modules[0]);