AvoidSpinlockCheck.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. //===--- AvoidSpinlockCheck.cpp - clang-tidy-------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "AvoidSpinlockCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/ASTMatchers/ASTMatchFinder.h"
  11. using namespace clang::ast_matchers;
  12. namespace clang::tidy::darwin {
  13. void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
  14. Finder->addMatcher(
  15. callExpr(callee((functionDecl(hasAnyName(
  16. "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry")))))
  17. .bind("spinlock"),
  18. this);
  19. }
  20. void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
  21. const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>("spinlock");
  22. diag(MatchedExpr->getBeginLoc(),
  23. "use os_unfair_lock_lock() or dispatch queue APIs instead of the "
  24. "deprecated OSSpinLock");
  25. }
  26. } // namespace clang::tidy::darwin