Skip to content

Conversation

@noclowns
Copy link
Contributor

@noclowns noclowns commented Oct 30, 2025

This patch addresses two use-after-move issues:

  1. Timing.cpp A variable was std::moved and then immediately passed to an assert() check. Since the moved-from state made the assertion condition trivially true, the check was effectively useless. The assert() is removed.

  2. Query.cpp The matcher object was moved-from and then subsequently used as if it still retained valid state. The fix ensures no subsequent use for the moved-from variable.

Testing:
ninja check-mlir

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 30, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Slava Gurevich (noclowns)

Changes

This patch addresses two use-after-move issues:

  1. Timing.cpp A variable was std::moved and then immediately passed to an assert() check. Since the moved-from state made the assertion condition trivially true, the check was effectively useless. The assert() is removed.

  2. Query.cpp The matcher object was moved-from and then subsequently used as if it still retained valid state. The fix removes the std::move to preserve the original object. It is possible to restructure the surrounding logic to maintain the move semantics, but doing so would reduce clarity. If needed, such restructuring can be considered later based on performance profiling.

Testing:
ninja check-mlir


Full diff: https://github.com/llvm/llvm-project/pull/165660.diff

2 Files Affected:

  • (modified) mlir/lib/Query/Query.cpp (+1-1)
  • (modified) mlir/lib/Support/Timing.cpp (-1)
diff --git a/mlir/lib/Query/Query.cpp b/mlir/lib/Query/Query.cpp
index 375e82050a481..f391734def000 100644
--- a/mlir/lib/Query/Query.cpp
+++ b/mlir/lib/Query/Query.cpp
@@ -121,7 +121,7 @@ LogicalResult MatchQuery::run(llvm::raw_ostream &os, QuerySession &qs) const {
   Operation *rootOp = qs.getRootOp();
   int matchCount = 0;
   matcher::MatchFinder finder;
-  auto matches = finder.collectMatches(rootOp, std::move(matcher));
+  auto matches = finder.collectMatches(rootOp, matcher);
 
   // An extract call is recognized by considering if the matcher has a name.
   // TODO: Consider making the extract more explicit.
diff --git a/mlir/lib/Support/Timing.cpp b/mlir/lib/Support/Timing.cpp
index fb6f82c283df5..16306d72815f7 100644
--- a/mlir/lib/Support/Timing.cpp
+++ b/mlir/lib/Support/Timing.cpp
@@ -319,7 +319,6 @@ class TimerImpl {
   void mergeChildren(AsyncChildrenMap &&other) {
     for (auto &thread : other) {
       mergeChildren(std::move(thread.second));
-      assert(thread.second.empty());
     }
     other.clear();
   }

@noclowns noclowns changed the title [MLIR] Fix use-after-move issues [mlir] Fix use-after-move issues Oct 30, 2025
This patch addresses two use-after-move issues:

1. Timing.cpp
A variable was std::moved and then immediately passed to an assert() check. Since the moved-from state made the assertion condition trivially true, the check was effectively useless. The assert() is removed.

2. Query.cpp
The `matcher` object was moved-from and then subsequently used as if it still retained valid state. The fix ensures no subsequent use of the moved-from variable.

Testing:
ninja check-mlir
@noclowns noclowns merged commit 98ceb45 into llvm:main Oct 30, 2025
10 checks passed
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
This patch addresses two use-after-move issues:

1. `Timing.cpp` A variable was std::moved and then immediately passed to
an `assert()` check. Since the moved-from state made the assertion
condition trivially true, the check was effectively useless. The
`assert()` is removed.

2. `Query.cpp` The `matcher` object was moved-from and then subsequently
used as if it still retained valid state. The fix ensures no subsequent
use for the moved-from variable.

Testing:
`ninja check-mlir`
luciechoi pushed a commit to luciechoi/llvm-project that referenced this pull request Nov 1, 2025
This patch addresses two use-after-move issues:

1. `Timing.cpp` A variable was std::moved and then immediately passed to
an `assert()` check. Since the moved-from state made the assertion
condition trivially true, the check was effectively useless. The
`assert()` is removed.

2. `Query.cpp` The `matcher` object was moved-from and then subsequently
used as if it still retained valid state. The fix ensures no subsequent
use for the moved-from variable.

Testing:
`ninja check-mlir`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants