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