[Mlir-commits] [mlir] [mlir][spirv] Check output of getConstantInt (PR #140568)

Igor Wodiany llvmlistbot at llvm.org
Mon May 19 09:14:22 PDT 2025


https://github.com/IgWod-IMG created https://github.com/llvm/llvm-project/pull/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 occurred when the value was defined as OpSpecConstant rather than OpConstant.

>From afd991cc18f3b7c10294850686ab435bd192cb34 Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Mon, 19 May 2025 17:04:42 +0100
Subject: [PATCH] [mlir][spirv] Check output of getConstantInt

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 occurred
when the value was defined as OpSpecConstant rather than OpConstant.
---
 .../Target/SPIRV/Deserialization/Deserializer.cpp | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 7afd6e9b25b77..9008d88866f40 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -1061,12 +1061,19 @@ LogicalResult spirv::Deserializer::processCooperativeMatrixTypeKHR(
            << operands[2];
   }
 
-  unsigned rows = getConstantInt(operands[3]).getInt();
-  unsigned columns = getConstantInt(operands[4]).getInt();
+  IntegerAttr rowsAttr = getConstantInt(operands[3]);
+  assert(rowsAttr);
+  unsigned rows = rowsAttr.getInt();
+
+  IntegerAttr columnsAttr = getConstantInt(operands[4]);
+  assert(columnsAttr);
+  unsigned columns = columnsAttr.getInt();
+
+  IntegerAttr useAttr = getConstantInt(operands[5]);
+  assert(useAttr);
 
   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