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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jun 18 08:10:40 PDT 2026


Author: Balaji V. Iyer.
Date: 2026-06-18T10:10:35-05:00
New Revision: de53dd06a2c3a3f4c58f057773bbfc0863f1fb75

URL: https://github.com/llvm/llvm-project/commit/de53dd06a2c3a3f4c58f057773bbfc0863f1fb75
DIFF: https://github.com/llvm/llvm-project/commit/de53dd06a2c3a3f4c58f057773bbfc0863f1fb75.diff

LOG: Added a check for unsigned integer before accessing (#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.

Added: 
    

Modified: 
    mlir/test/Analysis/DataFlow/test-staged-analyses.mlir
    mlir/test/lib/Analysis/TestDataFlowFramework.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/Analysis/DataFlow/test-staged-analyses.mlir b/mlir/test/Analysis/DataFlow/test-staged-analyses.mlir
index 5da7ad8bf1274..740b648078f75 100644
--- a/mlir/test/Analysis/DataFlow/test-staged-analyses.mlir
+++ b/mlir/test/Analysis/DataFlow/test-staged-analyses.mlir
@@ -48,3 +48,18 @@ func.func @requires_staged_bar() {
   // CHECK: "test.branch"()[^bb{{[0-9]+}}] {bar_state = true, foo = 2 : ui64, foo_state = 5 : i64, tag = "annotate"} : () -> ()
   "test.branch"() [^bb1] {tag = "annotate", foo = 2 : ui64} : () -> ()
 }
+
+// -----
+
+// 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