2017-09-13 04:00:42 +08:00
|
|
|
//===--- OwningMemoryCheck.h - clang-tidy------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-13 04:00:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
|
|
|
|
|
2020-06-29 23:05:51 +08:00
|
|
|
#include "../ClangTidyCheck.h"
|
2017-09-13 04:00:42 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace cppcoreguidelines {
|
|
|
|
|
|
|
|
/// Checks for common use cases for gsl::owner and enforces the unique owner
|
|
|
|
/// nature of it whenever possible.
|
|
|
|
///
|
|
|
|
/// For the user-facing documentation see:
|
|
|
|
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
|
|
|
|
class OwningMemoryCheck : public ClangTidyCheck {
|
|
|
|
public:
|
|
|
|
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
|
[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
2017-10-19 00:14:15 +08:00
|
|
|
: ClangTidyCheck(Name, Context),
|
|
|
|
LegacyResourceProducers(Options.get(
|
|
|
|
"LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
|
|
|
|
"::calloc;::fopen;::freopen;::tmpfile")),
|
|
|
|
LegacyResourceConsumers(Options.get(
|
|
|
|
"LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
|
|
|
|
}
|
[clang-tidy] Change checks to use new isLanguageVersionSupported restriction
Summary: Modifies all checks that are language version dependent to use `isLanguageVersionSupported`
Reviewers: jdoerfert, lebedev.ri, aaron.ballman, gribozavr2, Eugene.Zelenko
Reviewed By: gribozavr2
Subscribers: wuzish, nemanjai, xazax.hun, hiraditya, kbarton, steven_wu, dexonsmith, arphaman, lebedev.ri, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75340
2020-03-04 00:39:32 +08:00
|
|
|
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
|
|
|
|
return LangOpts.CPlusPlus11;
|
|
|
|
}
|
[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
2017-10-19 00:14:15 +08:00
|
|
|
|
|
|
|
/// Make configuration of checker discoverable.
|
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
|
|
|
|
2017-09-13 04:00:42 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
|
[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
2017-10-19 00:14:15 +08:00
|
|
|
bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
|
2017-09-13 04:00:42 +08:00
|
|
|
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);
|
[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
2017-10-19 00:14:15 +08:00
|
|
|
|
|
|
|
/// 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;
|
2017-09-13 04:00:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cppcoreguidelines
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
|