clang-tools  8.0.0
AvoidSpinlockCheck.cpp
Go to the documentation of this file.
1 //===--- 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 
14 using namespace clang::ast_matchers;
15 
16 namespace clang {
17 namespace tidy {
18 namespace objc {
19 
20 void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
21  Finder->addMatcher(
22  callExpr(callee((functionDecl(hasAnyName(
23  "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry")))))
24  .bind("spinlock"),
25  this);
26 }
27 
28 void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
29  const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>("spinlock");
30  diag(MatchedExpr->getBeginLoc(),
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
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//