<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154764>154764</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-tidy invalid suggestion: modernize-loop-convert
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
joker-eph
</td>
</tr>
</table>
<pre>
With clang-tidy built at current head and applying it on MLIR:
```
$ clang-tidy -p build mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp --checks=-*,modernize-loop-convert -fix -fix-errors
```
```
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 68ef51992efe..e5c3710971d4 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -307,8 +307,7 @@ LogicalResult bufferization::bufferizeOp(Operation *op,
// Bufferize all ops.
BufferizationRewriter rewriter(op->getContext(), erasedOps, toBufferOps,
worklist, options, statistics);
- for (unsigned i = 0; i < worklist.size(); ++i) {
- Operation *nextOp = worklist[i];
+ for (auto nextOp : worklist) {
// Skip ops that were erased.
if (erasedOps.contains(nextOp))
continue;
```
`worklist` is a vector: however there is a callback that will `push_back()` to the `worklist` , which can cause reallocation of the vector and iterator invalidation here.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVVuPqzYQ_jWTlxHImEvggYck20iVTrXStlIfK2MG8FkHI9tkL7--MrDZiyr14WxkBdvj-eabb_AgnFP9SFRDfoT8bidmPxhb_zSPZCOahl1j2pf6b-UHlFqMfeRV-4LNrLRH4VHO1tLocSDRohhbFNOkX9TYo_JoRvzjx-8PkB6ALaNg22AH4NlHwGhaMFu8aGWBn7VqgJ_vlNAkPfDzce46supVeGVG4Oe_rBhdZ-zFfT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