10#include "../utils/ExprSequence.h"
11#include "../utils/Matchers.h"
12#include "../utils/OptionsUtils.h"
13#include "clang/AST/ASTContext.h"
14#include "clang/ASTMatchers/ASTMatchFinder.h"
15#include "clang/Analysis/CFG.h"
26 auto LockType = elaboratedType(namesType(templateSpecializationType(
30 StatementMatcher Lock =
31 declStmt(has(varDecl(hasType(LockType)).bind(
"lock-decl")))
32 .bind(
"lock-decl-stmt");
34 expr(anyOf(coawaitExpr(), coyieldExpr(), dependentCoawaitExpr()),
35 forCallable(functionDecl().bind(
"function")),
36 unless(isInTemplateInstantiation()),
38 compoundStmt(has(Lock), forCallable(equalsBoundNode(
"function")))
45 const auto *Block = Result.Nodes.getNodeAs<CompoundStmt>(
"block");
46 const auto *Suspend = Result.Nodes.getNodeAs<Expr>(
"suspend");
47 const auto *LockDecl = Result.Nodes.getNodeAs<VarDecl>(
"lock-decl");
48 const auto *LockStmt = Result.Nodes.getNodeAs<Stmt>(
"lock-decl-stmt");
50 if (!Block || !Suspend || !LockDecl || !LockStmt)
53 ASTContext &Context = *Result.Context;
55 Options.AddImplicitDtors =
true;
56 Options.AddTemporaryDtors =
true;
58 std::unique_ptr<CFG> TheCFG = CFG::buildCFG(
59 nullptr,
const_cast<clang::CompoundStmt *
>(Block), &Context,
Options);
64 const Stmt *LastBlockStmt = Block->body_back();
65 if (Sequence.inSequence(LockStmt, Suspend) &&
66 (Suspend == LastBlockStmt ||
67 Sequence.inSequence(Suspend, LastBlockStmt))) {
68 diag(Suspend->getBeginLoc(),
"coroutine suspended with lock %0 held")
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
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 storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Provides information about the evaluation order of (sub-)expressions within a CFGBlock.
inline ::clang::ast_matchers::internal::Matcher< NamedDecl > matchesAnyListedName(llvm::ArrayRef< StringRef > NameList)
std::vector< StringRef > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
llvm::StringMap< ClangTidyValue > OptionMap