diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td --- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td +++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td @@ -263,8 +263,9 @@ /// Returns the number of buffers located in the workgroup memory. unsigned getNumWorkgroupAttributions() { - return (*this)->getAttrOfType( - getNumWorkgroupAttributionsAttrName()).getInt(); + auto attr = (*this)->getAttrOfType( + getNumWorkgroupAttributionsAttrName()); + return attr ? attr.getInt() : 0; } /// Returns a list of block arguments that correspond to buffers located in diff --git a/mlir/test/Dialect/GPU/ops.mlir b/mlir/test/Dialect/GPU/ops.mlir --- a/mlir/test/Dialect/GPU/ops.mlir +++ b/mlir/test/Dialect/GPU/ops.mlir @@ -284,3 +284,10 @@ return } } + +// Just check that this doesn't crash. +gpu.module @module { + "gpu.func"() ({ + gpu.return + }) {function_type = () -> (), sym_name = "func"} : () -> () +}