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//===----------------------------------------------------------------------===//
8
9#include "ThreadCanceltypeAsynchronousCheck.h"
10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/Preprocessor.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang::tidy::concurrency {
17
18void ThreadCanceltypeAsynchronousCheck::registerMatchers(MatchFinder *Finder) {
19 Finder->addMatcher(
20 NodeMatch: callExpr(
21 callee(InnerMatcher: functionDecl(hasName(Name: "::pthread_setcanceltype"))),
22 argumentCountIs(N: 2),
23 hasArgument(N: 0, InnerMatcher: isExpandedFromMacro(MacroName: "PTHREAD_CANCEL_ASYNCHRONOUS")))
24 .bind(ID: "setcanceltype"),
25 Action: this);
26}
27
28void ThreadCanceltypeAsynchronousCheck::check(
29 const MatchFinder::MatchResult &Result) {
30 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(ID: "setcanceltype");
31 diag(MatchedExpr->getBeginLoc(), "the cancel type for a pthread should not "
32 "be 'PTHREAD_CANCEL_ASYNCHRONOUS'");
33}
34
35} // namespace clang::tidy::concurrency
36

source code of clang-tools-extra/clang-tidy/concurrency/ThreadCanceltypeAsynchronousCheck.cpp