clang-tools  14.0.0git
ThreadCanceltypeAsynchronousCheck.cpp
Go to the documentation of this file.
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 
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/Lex/Preprocessor.h"
13 
14 using namespace clang::ast_matchers;
15 
16 namespace clang {
17 namespace tidy {
18 namespace concurrency {
19 
20 void ThreadCanceltypeAsynchronousCheck::registerMatchers(MatchFinder *Finder) {
21  Finder->addMatcher(
22  callExpr(
23  allOf(callee(functionDecl(hasName("::pthread_setcanceltype"))),
24  argumentCountIs(2)),
25  hasArgument(0, isExpandedFromMacro("PTHREAD_CANCEL_ASYNCHRONOUS")))
26  .bind("setcanceltype"),
27  this);
28 }
29 
31  const MatchFinder::MatchResult &Result) {
32  const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("setcanceltype");
33  diag(MatchedExpr->getBeginLoc(), "the cancel type for a pthread should not "
34  "be 'PTHREAD_CANCEL_ASYNCHRONOUS'");
35 }
36 
37 } // namespace concurrency
38 } // namespace tidy
39 } // namespace clang
ThreadCanceltypeAsynchronousCheck.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::clangd::check
bool check(llvm::StringRef File, llvm::function_ref< bool(const Position &)> ShouldCheckLine, const ThreadsafeFS &TFS, const ClangdLSPServer::Options &Opts, bool EnableCodeCompletion)
Definition: Check.cpp:258
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27