[Mlir-commits] [mlir] Added a check for unsigned integer before accessing (PR #204276)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jun 16 20:27:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Balaji V. Iyer. (bviyer)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/204276.diff
2 Files Affected:
- (added) mlir/test/Analysis/test-dataflow-framework.mlir (+14)
- (modified) mlir/test/lib/Analysis/TestDataFlowFramework.cpp (+3-1)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/204276
More information about the Mlir-commits
mailing list