[Mlir-commits] [mlir] 50c33a3 - [MLIR] Harden gpu.func verification

Christian Sigg llvmlistbot at llvm.org
Tue Aug 23 05:59:00 PDT 2022


Author: Christian Sigg
Date: 2022-08-23T14:58:46+02:00
New Revision: 50c33a3a9cb654cd659e134a90a3242e9544eba5

URL: https://github.com/llvm/llvm-project/commit/50c33a3a9cb654cd659e134a90a3242e9544eba5
DIFF: https://github.com/llvm/llvm-project/commit/50c33a3a9cb654cd659e134a90a3242e9544eba5.diff

LOG: [MLIR] Harden gpu.func verification

GPUFuncOpLowering moves the body out of gpu.func op and erases it. An empty gpu.func may fail verification but should not crash it. Verification of an erased op is triggered e.g. with debug printing on.

Reviewed By: akuegel

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

Added: 
    

Modified: 
    mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
    mlir/test/Dialect/GPU/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index d564f53521131..5d997325743a4 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -997,6 +997,8 @@ static LogicalResult verifyAttributions(Operation *op,
 
 /// Verifies the body of the function.
 LogicalResult GPUFuncOp::verifyBody() {
+  if (empty())
+    return emitOpError() << "expected body with at least one block";
   unsigned numFuncArguments = getNumArguments();
   unsigned numWorkgroupAttributions = getNumWorkgroupAttributions();
   unsigned numBlockArguments = front().getNumArguments();

diff  --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir
index 877ba26ce7619..b48938c486bee 100644
--- a/mlir/test/Dialect/GPU/invalid.mlir
+++ b/mlir/test/Dialect/GPU/invalid.mlir
@@ -421,6 +421,15 @@ module {
 
 // -----
 
+module {
+  gpu.module @gpu_funcs {
+    // expected-error @+1 {{expected body with at least one block}}
+    "gpu.func"() ({}) {function_type = () -> (), gpu.kernel, sym_name = "kernel"} : () -> ()
+  }
+}
+
+// -----
+
 func.func @sync_wait_with_result() {
   // expected-error @+1 {{cannot name an operation with no results}}
   %t = gpu.wait


        


More information about the Mlir-commits mailing list