[PATCH] D120956: [clang][AST matchers] new AST matcher argumentsGivenCountIs(n) that checks the actual number of arguments given in a function call

Alister Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 15 17:11:06 PDT 2022


ajohnson-uoregon added a comment.

This is the same use case as my other patches :) https://github.com/ajohnson-uoregon/llvm-project/blob/feature-ajohnson/clang-tools-extra/clang-rewrite/ConstructMatchers.cpp#L545

If there's a function with default arguments, and our user doesn't specify some of those defaults when they're writing code for our tool, we want to match only the calls in their code that give the same number of arguments, but `argumentCountIs()` matches the total *including* default arguments, and we need the total *excluding* non-provided default arguments. For example, our user might write

  void func(int a = 0, int b = 0);
  
  [[clang::matcher("test")]]
  auto foo(int x) {
    func(x);
  }

and we don't want that to match `func()` or `func(x, y)`. When we're doing matcher generation, we aren't able to look up the FunctionDecl and see if there are defaults (because the function name itself might be a parameter for us), and even if we could, adding `cxxDefaultArgExpr()` for all of the missing ones is a lot of work that we'd rather not do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120956/new/

https://reviews.llvm.org/D120956



More information about the cfe-commits mailing list