[Mlir-commits] [mlir] 466aa58 - [mlir][spirv] Fix crash in spirv-lower-abi-attributes
Jakub Kuderski
llvmlistbot at llvm.org
Fri Jan 13 08:00:49 PST 2023
Author: Jakub Kuderski
Date: 2023-01-13T10:59:48-05:00
New Revision: 466aa585c6dfb096bf9a7ad9bcbc6ce8cc7abff1
URL: https://github.com/llvm/llvm-project/commit/466aa585c6dfb096bf9a7ad9bcbc6ce8cc7abff1
DIFF: https://github.com/llvm/llvm-project/commit/466aa585c6dfb096bf9a7ad9bcbc6ce8cc7abff1.diff
LOG: [mlir][spirv] Fix crash in spirv-lower-abi-attributes
... when the are no SPIR-V env attributes.
Fixes: https://github.com/llvm/llvm-project/issues/59983
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D141695
Added:
Modified:
mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
index 2a13d4a65648b..c0ab2152675ee 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
@@ -274,7 +274,12 @@ void LowerABIAttributesPass::runOnOperation() {
spirv::ModuleOp module = getOperation();
MLIRContext *context = &getContext();
- spirv::TargetEnv targetEnv(spirv::lookupTargetEnv(module));
+ spirv::TargetEnvAttr targetEnvAttr = spirv::lookupTargetEnv(module);
+ if (!targetEnvAttr) {
+ module->emitOpError("missing SPIR-V target env attribute");
+ return signalPassFailure();
+ }
+ spirv::TargetEnv targetEnv(targetEnvAttr);
SPIRVTypeConverter typeConverter(targetEnv);
diff --git a/mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir b/mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir
index 4795a13bc9888..77e92da3504c6 100644
--- a/mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir
+++ b/mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-opt -split-input-file -spirv-lower-abi-attrs %s | FileCheck %s
+// RUN: mlir-opt --split-input-file --spirv-lower-abi-attrs --verify-diagnostics %s \
+// RUN: | FileCheck %s
module attributes {
spirv.target_env = #spirv.target_env<
@@ -31,3 +32,10 @@ spirv.module Logical GLSL450 {
} // end spirv.module
} // end module
+
+// -----
+
+module {
+// expected-error at +1 {{'spirv.module' op missing SPIR-V target env attribute}}
+spirv.module Logical GLSL450 {}
+} // end module
More information about the Mlir-commits
mailing list