[clang-tools-extra] [clang-tidy] Improve performance-use-std-move in presence of control-flow (PR #184136)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 8 05:56:54 PDT 2026
https://github.com/zeyi2 commented:
On second thought, there may be an uncovered corner case:
The backward worklist only pushes a block when `RemainingSuccessors` becomes 0. When we encounter a CFG with cycles, blocks in the cycle never get all their successors processed (have at least one successor that is also in the cycle), so they never enter the worklist and are never analyzed.
Repro;
```cpp
namespace std {
template <class T> struct remove_reference { typedef T type; };
template <class T> struct remove_reference<T&> { typedef T type; };
template <class T> struct remove_reference<T&&> { typedef T type; };
template <class T>
constexpr typename remove_reference<T>::type&& move(T&& t) noexcept;
}
struct NonTrivialMoveAssign {
NonTrivialMoveAssign() = default;
NonTrivialMoveAssign(const NonTrivialMoveAssign&) = default;
NonTrivialMoveAssign& operator=(const NonTrivialMoveAssign&);
NonTrivialMoveAssign& operator=(NonTrivialMoveAssign&&);
void stuff();
};
void linear_assign_no_use_after(NonTrivialMoveAssign& target, NonTrivialMoveAssign source) {
target = source; // warning here
(void)0;
}
// algorithm never processes loop block
void loop_assign_no_use_after(unsigned n, NonTrivialMoveAssign& target, NonTrivialMoveAssign source) {
while (n--) {
target = source; // no warning
}
(void)0; // source not used after loop
}
```
TBH I don't have idea on how to fix this issue. It seems that we may have to handle cycles explicitly. Keeping the current conservative behavior for loops may be acceptable, but a `// TODO` in the comments would be nice :)
https://github.com/llvm/llvm-project/pull/184136
More information about the cfe-commits
mailing list