[Mlir-commits] [mlir] [MLIR] Fix use-after-move for DEBUG builds (PR #164763)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 22 23:48:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Slava Gurevich (noclowns)
<details>
<summary>Changes</summary>
Fix use-after-move issues that occur only in DEBUG builds.
In one, constructor arguments are moved in the initializer list to initialize member variables, but the function body mistakenly accesses the moved-from arguments instead of the corresponding class members with identical names. While this is a UB, here it actually renders the affected asserts ineffective, since the comparisons operate on two hollowed-out objects, by implementation.
In a second fix, a variable is moved from within an assert, introducing a side effect that alters its subsequent use and causes divergence between DEBUG and RELEASE builds.
Testing:
ninja check-llvm
ninja check-llvm-unit
---
Full diff: https://github.com/llvm/llvm-project/pull/164763.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h (+2-4)
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/Utils/IterationGraphSorter.cpp (+3-3)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h
index d0a3f01afe871..43e48a6d34026 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h
@@ -158,16 +158,14 @@ namespace sparse_tensor {
/// Convenience method to abbreviate casting `getType()`.
template <typename T>
inline RankedTensorType getRankedTensorType(T &&t) {
- assert(static_cast<bool>(std::forward<T>(t)) &&
- "getRankedTensorType got null argument");
+ assert(static_cast<bool>(t) && "getRankedTensorType got null argument");
return dyn_cast<RankedTensorType>(std::forward<T>(t).getType());
}
/// Convenience method to abbreviate casting `getType()`.
template <typename T>
inline MemRefType getMemRefType(T &&t) {
- assert(static_cast<bool>(std::forward<T>(t)) &&
- "getMemRefType got null argument");
+ assert(static_cast<bool>(t) && "getMemRefType got null argument");
return cast<MemRefType>(std::forward<T>(t).getType());
}
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/IterationGraphSorter.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/IterationGraphSorter.cpp
index 73e0f3d2891d7..c70fd3b010406 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/IterationGraphSorter.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/IterationGraphSorter.cpp
@@ -159,12 +159,12 @@ IterationGraphSorter::IterationGraphSorter(
loop2OutLvl(loop2OutLvl), iterTypes(std::move(iterTypes)),
strategy(strategy) {
// One map per tensor.
- assert(loop2InsLvl.size() == ins.size());
+ assert(this->loop2InsLvl.size() == this->ins.size());
// All the affine maps have the same number of dimensions (loops).
assert(llvm::all_equal(llvm::map_range(
- loop2InsLvl, [](AffineMap m) { return m.getNumDims(); })));
+ this->loop2InsLvl, [](AffineMap m) { return m.getNumDims(); })));
// The number of results of the map should match the rank of the tensor.
- assert(llvm::all_of(llvm::zip(loop2InsLvl, ins), [](auto mvPair) {
+ assert(llvm::all_of(llvm::zip(this->loop2InsLvl, this->ins), [](auto mvPair) {
auto [m, v] = mvPair;
return m.getNumResults() == cast<ShapedType>(v.getType()).getRank();
}));
``````````
</details>
https://github.com/llvm/llvm-project/pull/164763
More information about the Mlir-commits
mailing list