[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang-tools-extra / clang-tidy / cppcoreguidelines / OwningMemoryCheck.h
blob3ab8f34b580f95088973ffb5f35f8920ec26a762
1 //===--- OwningMemoryCheck.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
12 #include "../ClangTidyCheck.h"
14 namespace clang::tidy::cppcoreguidelines {
16 /// Checks for common use cases for gsl::owner and enforces the unique owner
17 /// nature of it whenever possible.
18 ///
19 /// For the user-facing documentation see:
20 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/owning-memory.html
21 class OwningMemoryCheck : public ClangTidyCheck {
22 public:
23 OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
24 : ClangTidyCheck(Name, Context),
25 LegacyResourceProducers(Options.get(
26 "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
27 "::calloc;::fopen;::freopen;::tmpfile")),
28 LegacyResourceConsumers(Options.get(
29 "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
31 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
32 return LangOpts.CPlusPlus11;
35 /// Make configuration of checker discoverable.
36 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
38 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40 std::optional<TraversalKind> getCheckTraversalKind() const override {
41 return TK_IgnoreUnlessSpelledInSource;
44 private:
45 bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
46 bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
47 bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
48 bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
49 bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
50 bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
51 bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
53 /// List of old C-style functions that create resources.
54 /// Defaults to
55 /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
56 const StringRef LegacyResourceProducers;
57 /// List of old C-style functions that consume or release resources.
58 /// Defaults to `::free;::realloc;::freopen;::fclose`.
59 const StringRef LegacyResourceConsumers;
62 } // namespace clang::tidy::cppcoreguidelines
64 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H