[Mlir-commits] [mlir] [mlir][gpu] Validate `gpu-module-to-binary` format (PR #182842)

Akimasa Watanuki llvmlistbot at llvm.org
Mon Feb 23 04:49:24 PST 2026


https://github.com/Men-cotton created https://github.com/llvm/llvm-project/pull/182842

`GpuModuleToBinaryPass::runOnOperation` now treats an unsupported `format` value as a pass failure after emitting `"Invalid format specified."`.

Add a regression test in `mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir`.

Fix: https://github.com/llvm/llvm-project/issues/77052
Fix: https://github.com/llvm/llvm-project/issues/116344
Fix: https://github.com/llvm/llvm-project/issues/116346
Fix: https://github.com/llvm/llvm-project/issues/116352


>From b074e38cdad7750fbecf734b1b9cf715009d7419 Mon Sep 17 00:00:00 2001
From: mencotton <mencotton0410 at gmail.com>
Date: Mon, 23 Feb 2026 20:59:05 +0900
Subject: [PATCH] [mlir][gpu] Validate `gpu-module-to-binary` format

---
 mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp         | 4 +++-
 mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir

diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
index e359b8620b4ea..1452c67021c30 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
@@ -44,8 +44,10 @@ void GpuModuleToBinaryPass::runOnOperation() {
           .Cases({"binary", "bin"}, CompilationTarget::Binary)
           .Cases({"fatbinary", "fatbin"}, CompilationTarget::Fatbin)
           .Default(std::nullopt);
-  if (!targetFormat)
+  if (!targetFormat) {
     getOperation()->emitError() << "Invalid format specified.";
+    return signalPassFailure();
+  }
 
   // Lazy symbol table builder callback.
   std::optional<SymbolTable> parentTable;
diff --git a/mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir b/mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir
new file mode 100644
index 0000000000000..eb2c6dbc2be3f
--- /dev/null
+++ b/mlir/test/Dialect/GPU/module-to-binary-invalid-format.mlir
@@ -0,0 +1,5 @@
+// RUN: mlir-opt %s --gpu-module-to-binary="format=invalid-format" --verify-diagnostics
+
+// expected-error @+1 {{Invalid format specified.}}
+module attributes {gpu.container_module} {
+}



More information about the Mlir-commits mailing list