clang-tools 20.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
14using namespace clang::ast_matchers;
15
17
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);
26}
27
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'");
33}
34
35} // namespace clang::tidy::concurrency
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.