[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clang-tidy / concurrency / ThreadCanceltypeAsynchronousCheck.cpp
blob6ea9884a1a31ce680906461b6a76dd9c05527e95
1 //===--- ThreadCanceltypeAsynchronousCheck.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 //===----------------------------------------------------------------------===//
9 #include "ThreadCanceltypeAsynchronousCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/Lex/Preprocessor.h"
14 using namespace clang::ast_matchers;
16 namespace clang::tidy::concurrency {
18 void ThreadCanceltypeAsynchronousCheck::registerMatchers(MatchFinder *Finder) {
19 Finder->addMatcher(
20 callExpr(
21 callee(functionDecl(hasName("::pthread_setcanceltype"))),
22 argumentCountIs(2),
23 hasArgument(0, isExpandedFromMacro("PTHREAD_CANCEL_ASYNCHRONOUS")))
24 .bind("setcanceltype"),
25 this);
28 void ThreadCanceltypeAsynchronousCheck::check(
29 const MatchFinder::MatchResult &Result) {
30 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("setcanceltype");
31 diag(MatchedExpr->getBeginLoc(), "the cancel type for a pthread should not "
32 "be 'PTHREAD_CANCEL_ASYNCHRONOUS'");
35 } // namespace clang::tidy::concurrency