diff options
author | Shuai Wang <shuaiwang@google.com> | 2018-09-17 17:59:51 +0000 |
---|---|---|
committer | Shuai Wang <shuaiwang@google.com> | 2018-09-17 17:59:51 +0000 |
commit | 07eed56c96e3b2151f78166f3a430f9415a3a110 (patch) | |
tree | d9e25ebeb4548980b825e9414190183d22f94438 /clang-tidy/performance | |
parent | 00a59116251af48ae58c301873e4397b0261daeb (diff) |
[clang-tidy] Remove duplicated logic in UnnecessaryValueParamCheck and use FunctionParmMutationAnalyzer instead.
Reviewers: alexfh, JonasToth, george.karpenkov
Subscribers: xazax.hun, kristof.beyls, chrib, a.sidorin, Szelethus, cfe-commits
Differential Revision: https://reviews.llvm.org/D52158
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@342403 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/performance')
-rw-r--r-- | clang-tidy/performance/UnnecessaryValueParamCheck.cpp | 23 | ||||
-rw-r--r-- | clang-tidy/performance/UnnecessaryValueParamCheck.h | 4 |
2 files changed, 12 insertions, 15 deletions
diff --git a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp index 29a8b84c..db5a12f9 100644 --- a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp +++ b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp @@ -13,7 +13,6 @@ #include "../utils/FixItHintUtils.h" #include "../utils/Matchers.h" #include "../utils/TypeTraits.h" -#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" @@ -92,21 +91,11 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) { const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("param"); const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("functionDecl"); - // Do not trigger on non-const value parameters when they are mutated either - // within the function body or within init expression(s) when the function is - // a ctor. - if (ExprMutationAnalyzer(*Function->getBody(), *Result.Context) - .isMutated(Param)) + FunctionParmMutationAnalyzer &Analyzer = + MutationAnalyzers.try_emplace(Function, *Function, *Result.Context) + .first->second; + if (Analyzer.isMutated(Param)) return; - // CXXCtorInitializer might also mutate Param but they're not part of function - // body, so check them separately here. - if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Function)) { - for (const auto *Init : Ctor->inits()) { - if (ExprMutationAnalyzer(*Init->getInit(), *Result.Context) - .isMutated(Param)) - return; - } - } const bool IsConstQualified = Param->getType().getCanonicalType().isConstQualified(); @@ -186,6 +175,10 @@ void UnnecessaryValueParamCheck::storeOptions( utils::IncludeSorter::toString(IncludeStyle)); } +void UnnecessaryValueParamCheck::onEndOfTranslationUnit() { + MutationAnalyzers.clear(); +} + void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var, const DeclRefExpr &CopyArgument, const ASTContext &Context) { diff --git a/clang-tidy/performance/UnnecessaryValueParamCheck.h b/clang-tidy/performance/UnnecessaryValueParamCheck.h index cbf0a3bb..ae5ef7e9 100644 --- a/clang-tidy/performance/UnnecessaryValueParamCheck.h +++ b/clang-tidy/performance/UnnecessaryValueParamCheck.h @@ -12,6 +12,7 @@ #include "../ClangTidy.h" #include "../utils/IncludeInserter.h" +#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h" namespace clang { namespace tidy { @@ -29,11 +30,14 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; void registerPPCallbacks(CompilerInstance &Compiler) override; void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void onEndOfTranslationUnit() override; private: void handleMoveFix(const ParmVarDecl &Var, const DeclRefExpr &CopyArgument, const ASTContext &Context); + llvm::DenseMap<const FunctionDecl *, FunctionParmMutationAnalyzer> + MutationAnalyzers; std::unique_ptr<utils::IncludeInserter> Inserter; const utils::IncludeSorter::IncludeStyle IncludeStyle; }; |