[clang-tools-extra] [clang-tidy][mlir] Expand to cover pointer of builder (PR #159423)

Jacques Pienaar via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 23 05:01:48 PDT 2025


================
@@ -114,19 +123,17 @@ RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
   Stencil message = cat("use 'OpType::create(builder, ...)' instead of "
                         "'builder.create<OpType>(...)'");
   // Match a create call on an OpBuilder.
-  ast_matchers::internal::Matcher<Stmt> base =
-      cxxMemberCallExpr(
-          on(expr(hasType(
-                      cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"))))
-                 .bind("builder")),
-          callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument()))),
-          callee(cxxMethodDecl(hasName("create"))))
-          .bind("call");
+  auto BuilderType = cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"));
+  ast_matchers::internal::Matcher<Stmt> base = cxxMemberCallExpr(
+      on(expr(anyOf(hasType(BuilderType), hasType(pointsTo(BuilderType))))
+             .bind("builder")),
+      callee(expr().bind("call")),
+      callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument()))),
+      callee(cxxMethodDecl(hasName("create"))));
----------------
jpienaar wrote:

I can combine the two callee on cxxMethodDecl, but if I do the all combined it no longer matches

```
template <typename T>
void g(mlir::OpBuilder &b) {
  b.create<T>(b.getUnknownLoc(), "gaz");
}
```

https://github.com/llvm/llvm-project/pull/159423


More information about the cfe-commits mailing list