From 50c33a3a9cb654cd659e134a90a3242e9544eba5 Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Tue, 23 Aug 2022 12:45:49 +0200 Subject: [PATCH] [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 --- mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 2 ++ mlir/test/Dialect/GPU/invalid.mlir | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index d564f53..5d99732 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 877ba26..b48938c 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 -- 2.7.4