17dc7f0c2SBalázs Kéri //===--- ThreadCanceltypeAsynchronousCheck.cpp - clang-tidy ---------------===// 27dc7f0c2SBalázs Kéri // 37dc7f0c2SBalázs Kéri // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 47dc7f0c2SBalázs Kéri // See https://llvm.org/LICENSE.txt for license information. 57dc7f0c2SBalázs Kéri // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 67dc7f0c2SBalázs Kéri // 77dc7f0c2SBalázs Kéri //===----------------------------------------------------------------------===// 87dc7f0c2SBalázs Kéri 97dc7f0c2SBalázs Kéri #include "ThreadCanceltypeAsynchronousCheck.h" 107dc7f0c2SBalázs Kéri #include "clang/AST/ASTContext.h" 117dc7f0c2SBalázs Kéri #include "clang/ASTMatchers/ASTMatchFinder.h" 127dc7f0c2SBalázs Kéri #include "clang/Lex/Preprocessor.h" 137dc7f0c2SBalázs Kéri 147dc7f0c2SBalázs Kéri using namespace clang::ast_matchers; 157dc7f0c2SBalázs Kéri 167d2ea6c4SCarlos Galvez namespace clang::tidy::concurrency { 177dc7f0c2SBalázs Kéri registerMatchers(MatchFinder * Finder)187dc7f0c2SBalázs Kérivoid ThreadCanceltypeAsynchronousCheck::registerMatchers(MatchFinder *Finder) { 197dc7f0c2SBalázs Kéri Finder->addMatcher( 207dc7f0c2SBalázs Kéri callExpr( 21*df0c8f25SNathan James callee(functionDecl(hasName("::pthread_setcanceltype"))), 22*df0c8f25SNathan James argumentCountIs(2), 237dc7f0c2SBalázs Kéri hasArgument(0, isExpandedFromMacro("PTHREAD_CANCEL_ASYNCHRONOUS"))) 247dc7f0c2SBalázs Kéri .bind("setcanceltype"), 257dc7f0c2SBalázs Kéri this); 267dc7f0c2SBalázs Kéri } 277dc7f0c2SBalázs Kéri check(const MatchFinder::MatchResult & Result)287dc7f0c2SBalázs Kérivoid ThreadCanceltypeAsynchronousCheck::check( 297dc7f0c2SBalázs Kéri const MatchFinder::MatchResult &Result) { 307dc7f0c2SBalázs Kéri const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("setcanceltype"); 317dc7f0c2SBalázs Kéri diag(MatchedExpr->getBeginLoc(), "the cancel type for a pthread should not " 327dc7f0c2SBalázs Kéri "be 'PTHREAD_CANCEL_ASYNCHRONOUS'"); 337dc7f0c2SBalázs Kéri } 347dc7f0c2SBalázs Kéri 357d2ea6c4SCarlos Galvez } // namespace clang::tidy::concurrency 36