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 14 using namespace clang::ast_matchers; 15 16 namespace clang::tidy::concurrency { 17 registerMatchers(MatchFinder * Finder)18void 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); 26 } 27 check(const MatchFinder::MatchResult & Result)28void 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'"); 33 } 34 35 } // namespace clang::tidy::concurrency 36