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 | |
9 | #include "AvoidSpinlockCheck.h" |
10 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
11 | |
12 | using namespace clang::ast_matchers; |
13 | |
14 | namespace clang::tidy::darwin { |
15 | |
16 | void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) { |
17 | Finder->addMatcher( |
18 | NodeMatch: callExpr(callee(InnerMatcher: (functionDecl(hasAnyName( |
19 | "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry"))))) |
20 | .bind(ID: "spinlock"), |
21 | Action: this); |
22 | } |
23 | |
24 | void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) { |
25 | const auto *MatchedExpr = Result.Nodes.getNodeAs<CallExpr>(ID: "spinlock"); |
26 | diag(Loc: MatchedExpr->getBeginLoc(), |
27 | Description: "use os_unfair_lock_lock() or dispatch queue APIs instead of the " |
28 | "deprecated OSSpinLock"); |
29 | } |
30 | |
31 | } // namespace clang::tidy::darwin |
32 |