| 1 | //===--- CoroutineHostileRAIICheck.h - clang-tidy ----------------*- C++-*-===// |
| 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 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H |
| 10 | #define |
| 11 | |
| 12 | #include "../ClangTidyCheck.h" |
| 13 | #include "clang/AST/ASTTypeTraits.h" |
| 14 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace clang::tidy::misc { |
| 19 | |
| 20 | /// Detects when objects of certain hostile RAII types persists across |
| 21 | /// suspension points in a coroutine. Such hostile types include scoped-lockable |
| 22 | /// types and types belonging to a configurable denylist. |
| 23 | /// |
| 24 | /// For the user-facing documentation see: |
| 25 | /// http://clang.llvm.org/extra/clang-tidy/checks/misc/coroutine-hostile-raii.html |
| 26 | class CoroutineHostileRAIICheck : public ClangTidyCheck { |
| 27 | public: |
| 28 | CoroutineHostileRAIICheck(llvm::StringRef Name, ClangTidyContext *Context); |
| 29 | |
| 30 | bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { |
| 31 | return LangOpts.CPlusPlus20; |
| 32 | } |
| 33 | |
| 34 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 35 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 36 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 37 | |
| 38 | std::optional<TraversalKind> getCheckTraversalKind() const override { |
| 39 | return TK_AsIs; |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | // List of fully qualified types which should not persist across a suspension |
| 44 | // point in a coroutine. |
| 45 | std::vector<StringRef> RAIITypesList; |
| 46 | // List of fully qualified awaitable types which are considered safe to |
| 47 | // co_await. |
| 48 | std::vector<StringRef> AllowedAwaitablesList; |
| 49 | }; |
| 50 | |
| 51 | } // namespace clang::tidy::misc |
| 52 | |
| 53 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H |
| 54 | |