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

Darshan Bhat llvmlistbot at llvm.org
Wed Feb 18 10:22:56 PST 2026


https://github.com/darshan-opensource updated https://github.com/llvm/llvm-project/pull/182086

>From 92021dbd4ac6a43202ffa2ed6db6173295ff0db7 Mon Sep 17 00:00:00 2001
From: Darshan Bhat <darshanbhatsirsi at gmail.com>
Date: Wed, 18 Feb 2026 19:16:43 +0100
Subject: [PATCH] [mlir] Fix segfault in gpu.launch verifier when body region
 is empty

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.
---
 mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 10 ++++++----
 mlir/test/Dialect/GPU/invalid.mlir     |  9 +++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

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) ({



More information about the Mlir-commits mailing list