[Mlir-commits] [mlir] 3ce3281 - [mlir][spirv] Check output of getConstantInt (#140568)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 4 05:15:31 PDT 2025
Author: Igor Wodiany
Date: 2025-06-04T13:15:28+01:00
New Revision: 3ce32819894f15a9a82b62a7b87ba8b7b93128ef
URL: https://github.com/llvm/llvm-project/commit/3ce32819894f15a9a82b62a7b87ba8b7b93128ef
DIFF: https://github.com/llvm/llvm-project/commit/3ce32819894f15a9a82b62a7b87ba8b7b93128ef.diff
LOG: [mlir][spirv] Check output of getConstantInt (#140568)
This patch adds an assert to check if the result of `getConstantInt` is
non-null. Previously the code failed with Segmentation Fault if
`getConstantInt` failed to look up the value. This primarily occurrs when
the value is defined as OpSpecConstant rather than OpConstant.
Added:
Modified:
mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index a21d691ae5142..3957dbc0db984 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -1062,12 +1062,30 @@ LogicalResult spirv::Deserializer::processCooperativeMatrixTypeKHR(
<< operands[2];
}
- unsigned rows = getConstantInt(operands[3]).getInt();
- unsigned columns = getConstantInt(operands[4]).getInt();
+ IntegerAttr rowsAttr = getConstantInt(operands[3]);
+ IntegerAttr columnsAttr = getConstantInt(operands[4]);
+ IntegerAttr useAttr = getConstantInt(operands[5]);
+
+ if (!rowsAttr)
+ return emitError(unknownLoc, "OpTypeCooperativeMatrixKHR `Rows` references "
+ "undefined constant <id> ")
+ << operands[3];
+
+ if (!columnsAttr)
+ return emitError(unknownLoc, "OpTypeCooperativeMatrixKHR `Columns` "
+ "references undefined constant <id> ")
+ << operands[4];
+
+ if (!useAttr)
+ return emitError(unknownLoc, "OpTypeCooperativeMatrixKHR `Use` references "
+ "undefined constant <id> ")
+ << operands[5];
+
+ unsigned rows = rowsAttr.getInt();
+ unsigned columns = columnsAttr.getInt();
std::optional<spirv::CooperativeMatrixUseKHR> use =
- spirv::symbolizeCooperativeMatrixUseKHR(
- getConstantInt(operands[5]).getInt());
+ spirv::symbolizeCooperativeMatrixUseKHR(useAttr.getInt());
if (!use) {
return emitError(
unknownLoc,
More information about the Mlir-commits
mailing list