blob: 21ec3642184c0d6a581962e24319caa21cdeb241 [file] [log] [blame]
Yan Zhang2f20b362017-11-27 21:30:10 +00001//===--- AvoidSpinlockCheck.cpp - clang-tidy-------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "AvoidSpinlockCheck.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang {
17namespace tidy {
18namespace objc {
19
20void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
21 Finder->addMatcher(
22 callExpr(callee((functionDecl(hasAnyName(
23 "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry")))))
24 .bind("spinlock"),
25 this);
26}
27
28void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
29 const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>("spinlock");
30 diag(MatchedExpr->getLocStart(),
31 "use os_unfair_lock_lock() or dispatch queue APIs instead of the "
32 "deprecated OSSpinLock");
33}
34
35} // namespace objc
36} // namespace tidy
37} // namespace clang