[Mlir-commits] [mlir] [mlir] Fix segfault in gpu.launch verifier when body region is empty (PR #182086)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Feb 18 10:22:05 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Darshan Bhat (darshan-opensource)

<details>
<summary>Changes</summary>

Some methods in LaunchOp::verifyRegion() accesses body block without checking that region is empty resulting in a segfault. Fix by adding an early return when the body is empty.

---
Full diff: https://github.com/llvm/llvm-project/pull/182086.diff


2 Files Affected:

- (modified) mlir/lib/Dialect/GPU/IR/GPUDialect.cpp (+6-4) 
- (modified) mlir/test/Dialect/GPU/invalid.mlir (+9) 


``````````diff
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 5953553ae0df0..a66a83b7e3ca1 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -892,10 +892,12 @@ LogicalResult LaunchOp::verifyRegions() {
   // Kernel launch takes kNumConfigOperands leading operands for grid/block
   // sizes and transforms them into kNumConfigRegionAttributes region arguments
   // for block/thread identifiers and grid/block sizes.
-  if (!getBody().empty()) {
-    if (getBody().getNumArguments() <
-        kNumConfigRegionAttributes + getNumWorkgroupAttributions())
-      return emitOpError("unexpected number of region arguments");
+  if (getBody().empty()) {
+    return emitOpError("body region is empty");
+  }
+  if (getBody().getNumArguments() <
+      kNumConfigRegionAttributes + getNumWorkgroupAttributions()) {
+    return emitOpError("unexpected number of region arguments");
   }
 
   // Verify Attributions Address Spaces.
diff --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir
index 7c678e4f34d3d..20fe50469e0e4 100644
--- a/mlir/test/Dialect/GPU/invalid.mlir
+++ b/mlir/test/Dialect/GPU/invalid.mlir
@@ -1,5 +1,14 @@
 // RUN: mlir-opt -split-input-file -verify-diagnostics %s
 
+func.func @empty_body(%sz : index) {
+  // expected-error at +1 {{'gpu.launch' op body region is empty}}
+  "gpu.launch"(%sz, %sz, %sz, %sz, %sz, %sz) ({
+  }) {operandSegmentSizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0>} : (index, index, index, index, index, index) -> ()
+  return
+}
+
+// -----
+
 func.func @not_enough_sizes(%sz : index) {
   // expected-error at +1 {{expected 6 or more operands, but found 5}}
   "gpu.launch"(%sz, %sz, %sz, %sz, %sz) ({

``````````

</details>


https://github.com/llvm/llvm-project/pull/182086


More information about the Mlir-commits mailing list