[Mlir-commits] [mlir] [mlir][spirv] Check variable for null before dereferencing (PR #157457)

Daniel Kuts llvmlistbot at llvm.org
Mon Sep 8 08:45:37 PDT 2025


https://github.com/apach301 updated https://github.com/llvm/llvm-project/pull/157457

>From 1b58e779d945ed5f0bf390439171327754ee5038 Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 16:24:17 +0300
Subject: [PATCH 1/2] [mlir] Check variable for null before dereferencing in
 Dialect/SPIRV/IR

---
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index f99339852824c..7a6d4a212159b 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -727,9 +727,9 @@ void mlir::spirv::ConstantOp::getAsmResultNames(
       return setNameFn(getResult(), (intCst.getInt() ? "true" : "false"));
     }
 
-    if (intTy.isSignless()) {
+    if (intTy && intTy.isSignless()) {
       specialName << intCst.getInt();
-    } else if (intTy.isUnsigned()) {
+    } else if (intTy && intTy.isUnsigned()) {
       specialName << intCst.getUInt();
     } else {
       specialName << intCst.getSInt();

>From b1caf4d3290504aa56039ff51916cb442fdbaac6 Mon Sep 17 00:00:00 2001
From: Daniel Kuts <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 18:45:28 +0300
Subject: [PATCH 2/2] Change nullptr checks into assertion

---
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 7a6d4a212159b..55119984d9cc1 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -723,13 +723,15 @@ void mlir::spirv::ConstantOp::getAsmResultNames(
   IntegerType intTy = llvm::dyn_cast<IntegerType>(type);
 
   if (IntegerAttr intCst = llvm::dyn_cast<IntegerAttr>(getValue())) {
-    if (intTy && intTy.getWidth() == 1) {
+    assert(intTy);
+
+    if (intTy.getWidth() == 1) {
       return setNameFn(getResult(), (intCst.getInt() ? "true" : "false"));
     }
 
-    if (intTy && intTy.isSignless()) {
+    if (intTy.isSignless()) {
       specialName << intCst.getInt();
-    } else if (intTy && intTy.isUnsigned()) {
+    } else if (intTy.isUnsigned()) {
       specialName << intCst.getUInt();
     } else {
       specialName << intCst.getSInt();



More information about the Mlir-commits mailing list