1 //===--- ThreadCanceltypeAsynchronousCheck.cpp - clang-tidy ---------------===//
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
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
) {
21 callee(functionDecl(hasName("::pthread_setcanceltype"))),
23 hasArgument(0, isExpandedFromMacro("PTHREAD_CANCEL_ASYNCHRONOUS")))
24 .bind("setcanceltype"),
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