Skip to content

Commit 466aa58

Browse files
committed
[mlir][spirv] Fix crash in spirv-lower-abi-attributes
... when the are no SPIR-V env attributes. Fixes: #59983 Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D141695
1 parent f94131a commit 466aa58

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ void LowerABIAttributesPass::runOnOperation() {
274274
spirv::ModuleOp module = getOperation();
275275
MLIRContext *context = &getContext();
276276

277-
spirv::TargetEnv targetEnv(spirv::lookupTargetEnv(module));
277+
spirv::TargetEnvAttr targetEnvAttr = spirv::lookupTargetEnv(module);
278+
if (!targetEnvAttr) {
279+
module->emitOpError("missing SPIR-V target env attribute");
280+
return signalPassFailure();
281+
}
282+
spirv::TargetEnv targetEnv(targetEnvAttr);
278283

279284
SPIRVTypeConverter typeConverter(targetEnv);
280285

mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-opt -split-input-file -spirv-lower-abi-attrs %s | FileCheck %s
1+
// RUN: mlir-opt --split-input-file --spirv-lower-abi-attrs --verify-diagnostics %s \
2+
// RUN: | FileCheck %s
23

34
module attributes {
45
spirv.target_env = #spirv.target_env<
@@ -31,3 +32,10 @@ spirv.module Logical GLSL450 {
3132
} // end spirv.module
3233

3334
} // end module
35+
36+
// -----
37+
38+
module {
39+
// expected-error@+1 {{'spirv.module' op missing SPIR-V target env attribute}}
40+
spirv.module Logical GLSL450 {}
41+
} // end module

0 commit comments

Comments
 (0)