clang-tools 6.0.0

OwningMemoryCheck.h
Go to the documentation of this file.
1 //===--- OwningMemoryCheck.h - clang-tidy------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace cppcoreguidelines {
18
19 /// Checks for common use cases for gsl::owner and enforces the unique owner
20 /// nature of it whenever possible.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
24 class OwningMemoryCheck : public ClangTidyCheck {
25 public:
26 OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
27 : ClangTidyCheck(Name, Context),
28 LegacyResourceProducers(Options.get(
29 "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
30 "::calloc;::fopen;::freopen;::tmpfile")),
31 LegacyResourceConsumers(Options.get(
32 "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
33 }
34
35 /// Make configuration of checker discoverable.
36 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37
38 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40
41 private:
42 bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
43 bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
44 bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
45 bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
46 bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
47 bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
48 bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
49
50 /// List of old C-style functions that create resources.
51 /// Defaults to
52 /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
53 const std::string LegacyResourceProducers;
54 /// List of old C-style functions that consume or release resources.
55 /// Defaults to `::free;::realloc;::freopen;::fclose`.
56 const std::string LegacyResourceConsumers;
57 };
58
59 } // namespace cppcoreguidelines
60 } // namespace tidy
61 } // namespace clang
62
63 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::cppcoreguidelines::OwningMemoryCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Match common cases, where the owner semantic is relevant, like function calls, delete expressions and...
Definition: OwningMemoryCheck.cpp:42
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::cppcoreguidelines::OwningMemoryCheck::OwningMemoryCheck
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
Definition: OwningMemoryCheck.h:26
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidy.h:183
clang::tidy::cppcoreguidelines::OwningMemoryCheck
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
Definition: OwningMemoryCheck.h:24
clang::tidy::cppcoreguidelines::OwningMemoryCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition: OwningMemoryCheck.cpp:35
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::cppcoreguidelines::OwningMemoryCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: OwningMemoryCheck.cpp:182
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104