[Mlir-commits] [mlir] 59ba10b - [mlir][spirv] Fix crash when spirv.struct member type is not a SPIR-V type (#183942)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Feb 28 13:21:43 PST 2026
Author: Mehdi Amini
Date: 2026-02-28T22:21:38+01:00
New Revision: 59ba10b9d38a27e6783a64f21c0a4f56bccae126
URL: https://github.com/llvm/llvm-project/commit/59ba10b9d38a27e6783a64f21c0a4f56bccae126
DIFF: https://github.com/llvm/llvm-project/commit/59ba10b9d38a27e6783a64f21c0a4f56bccae126.diff
LOG: [mlir][spirv] Fix crash when spirv.struct member type is not a SPIR-V type (#183942)
When parsing a spirv.struct type, any MLIR type was accepted as a member
type without validation. This caused a crash in TypeExtensionVisitor and
TypeCapabilityVisitor which unconditionally used cast<SPIRVType> on
struct element types, asserting when a non-SPIR-V type (e.g.,
vector<2x2xi1>) was encountered.
Fix the parser to reject non-SPIR-V member types with a proper error
message.
Fixes #179675
Added:
Modified:
mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
mlir/test/Dialect/SPIRV/IR/types.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 78f33c238d414f..c9b22fe145d88f 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -774,6 +774,11 @@ static Type parseStructType(SPIRVDialect const &dialect,
Type memberType;
if (parser.parseType(memberType))
return Type();
+ if (!isa<SPIRVType>(memberType)) {
+ parser.emitError(parser.getNameLoc(),
+ "member type must be a valid SPIR-V type");
+ return Type();
+ }
memberTypes.push_back(memberType);
if (succeeded(parser.parseOptionalLSquare()))
diff --git a/mlir/test/Dialect/SPIRV/IR/types.mlir b/mlir/test/Dialect/SPIRV/IR/types.mlir
index 98509fb376acfb..710673b73cee59 100644
--- a/mlir/test/Dialect/SPIRV/IR/types.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/types.mlir
@@ -384,6 +384,12 @@ func.func private @struct_missing_member_decorator_value(!spirv.struct<(!spirv.m
// -----
+// Regression test for https://github.com/llvm/llvm-project/issues/179675
+// expected-error @+1 {{member type must be a valid SPIR-V type}}
+func.func private @struct_type_non_spirv_member(!spirv.struct<(vector<2x2xi1>)>) -> ()
+
+// -----
+
//===----------------------------------------------------------------------===//
// StructType (identified)
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list