clang-tools 10.0.0

OwningMemoryCheck.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
11
12 #include "../ClangTidy.h"
13
14 namespace clang {
15 namespace tidy {
16 namespace cppcoreguidelines {
17
18 /// Checks for common use cases for gsl::owner and enforces the unique owner
19 /// nature of it whenever possible.
20 ///
21 /// For the user-facing documentation see:
22 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
23 class OwningMemoryCheck : public ClangTidyCheck {
24 public:
25 OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
26 : ClangTidyCheck(Name, Context),
27 LegacyResourceProducers(Options.get(
28 "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
29 "::calloc;::fopen;::freopen;::tmpfile")),
30 LegacyResourceConsumers(Options.get(
31 "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
32 }
33
34 /// Make configuration of checker discoverable.
35 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36
37 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
38 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
39
40 private:
41 bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
42 bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
43 bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
44 bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
45 bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
46 bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
47 bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
48
49 /// List of old C-style functions that create resources.
50 /// Defaults to
51 /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
52 const std::string LegacyResourceProducers;
53 /// List of old C-style functions that consume or release resources.
54 /// Defaults to `::free;::realloc;::freopen;::fclose`.
55 const std::string LegacyResourceConsumers;
56 };
57
58 } // namespace cppcoreguidelines
59 } // namespace tidy
60 } // namespace clang
61
62 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
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:41
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::cppcoreguidelines::OwningMemoryCheck::OwningMemoryCheck
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
Definition: OwningMemoryCheck.h:25
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:184
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:23
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::cppcoreguidelines::OwningMemoryCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition: OwningMemoryCheck.cpp:34
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
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:177
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77