[Mlir-commits] [mlir] Added a check for unsigned integer before accessing (PR #204276)

Balaji V. Iyer. llvmlistbot at llvm.org
Tue Jun 16 20:20:33 PDT 2026


https://github.com/bviyer created https://github.com/llvm/llvm-project/pull/204276

Possible fix for #203862

Unsigned value is assumed but signed is possible. So added a check if it is unsigned before accessing as unsigned, otherwise access as integer and typecast to unsigned.

>From dc2a39459501dc4db6e29d8c2bf904f125cf6224 Mon Sep 17 00:00:00 2001
From: "Balaji V. Iyer" <bviyer at gmail.com>
Date: Tue, 16 Jun 2026 22:17:37 -0500
Subject: [PATCH] Added a check for unsigned integer before accessing

---
 mlir/test/Analysis/test-dataflow-framework.mlir  | 14 ++++++++++++++
 mlir/test/lib/Analysis/TestDataFlowFramework.cpp |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 mlir/test/Analysis/test-dataflow-framework.mlir

diff --git a/mlir/test/Analysis/test-dataflow-framework.mlir b/mlir/test/Analysis/test-dataflow-framework.mlir
new file mode 100644
index 0000000000000..ccb9f6a0721f8
--- /dev/null
+++ b/mlir/test/Analysis/test-dataflow-framework.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-opt -test-staged-analyses -split-input-file %s | FileCheck %s
+
+// Test that FooAnalysis does not crash when a func.func carries integer
+// attributes with signless i64 type (e.g. llvm.link_call_count).
+
+// CHECK-LABEL: func.func private @callee
+module {
+  func.func private @callee(%arg0: i32) -> i32 attributes {llvm.link_call_count = 10 : i64, sym.link_call_count = 11 : i64} {
+    %0:2 = "test.foo"() {foo = 5 : i32} : () -> (i32, i32)
+    %1 = "test.foo"() {foo = 7 : i32} : () -> i32
+    %2 = "test.hello"(%0#0, %1) : (i32, i32) -> i32
+    return %2 : i32
+  }
+}
diff --git a/mlir/test/lib/Analysis/TestDataFlowFramework.cpp b/mlir/test/lib/Analysis/TestDataFlowFramework.cpp
index 9af7e205aaee9..f29136853a9cd 100644
--- a/mlir/test/lib/Analysis/TestDataFlowFramework.cpp
+++ b/mlir/test/lib/Analysis/TestDataFlowFramework.cpp
@@ -239,7 +239,9 @@ void FooAnalysis::visitOperation(Operation *op) {
 
   // Modify the state with the attribute, if specified.
   if (auto attr = op->getAttrOfType<IntegerAttr>(kFooAttrName)) {
-    uint64_t value = attr.getUInt();
+    uint64_t value = attr.getType().isUnsignedInteger()
+                         ? attr.getUInt()
+                         : static_cast<uint64_t>(attr.getInt());
     result |= state->join(value);
   }
   propagateIfChanged(state, result);



More information about the Mlir-commits mailing list