| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 "../ClangTidyCheck.h" |
| 13 |
|
| 14 |
namespace clang::tidy::cppcoreguidelines { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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")) { |
| 30 |
} |
| 31 |
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { |
| 32 |
return LangOpts.CPlusPlus11; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 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 |
|
| 51 |
|
| 52 |
|
| 53 |
const StringRef LegacyResourceProducers; |
| 54 |
|
| 55 |
|
| 56 |
const StringRef LegacyResourceConsumers; |
| 57 |
}; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
#endif |