summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2017-10-18 16:14:15 +0000
committerJonas Toth <jonas.toth@gmail.com>2017-10-18 16:14:15 +0000
commitc9aea86e6af2bc1f7414f69f31428cf49273bf62 (patch)
treeeb9d59a48d895e2799a488c3b416a79a7d66bc89 /clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
parent13ce95b77f54aa4a7ff01a46a5faaa85001755a6 (diff)
downloadbcm5719-llvm-c9aea86e6af2bc1f7414f69f31428cf49273bf62.tar.gz
bcm5719-llvm-c9aea86e6af2bc1f7414f69f31428cf49273bf62.zip
[clang-tidy] introduce legacy resource functions to 'cppcoreguidelines-owning-memory'
Summary: This patch introduces support for legacy C-style resource functions that must obey the 'owner<>' semantics. - added legacy creators like malloc,fopen,... - added legacy consumers like free,fclose,... This helps codes that mostly benefit from owner: Legacy, C-Style code that isn't feasable to port directly to RAII but needs a step in between to identify actual resource management and just using the resources. Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38396 llvm-svn: 316092
Diffstat (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h')
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
index 60c40bc710b..e68e4c09b12 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
@@ -24,17 +24,36 @@ namespace cppcoreguidelines {
class OwningMemoryCheck : public ClangTidyCheck {
public:
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ : ClangTidyCheck(Name, Context),
+ LegacyResourceProducers(Options.get(
+ "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
+ "::calloc;::fopen;::freopen;::tmpfile")),
+ LegacyResourceConsumers(Options.get(
+ "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
+ }
+
+ /// Make configuration of checker discoverable.
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
private:
bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
+ bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
+
+ /// List of old C-style functions that create resources.
+ /// Defaults to
+ /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
+ const std::string LegacyResourceProducers;
+ /// List of old C-style functions that consume or release resources.
+ /// Defaults to `::free;::realloc;::freopen;::fclose`.
+ const std::string LegacyResourceConsumers;
};
} // namespace cppcoreguidelines
OpenPOWER on IntegriCloud