[clang-tools-extra] r342403 - [clang-tidy] Remove duplicated logic in UnnecessaryValueParamCheck and use FunctionParmMutationAnalyzer instead.
Shuai Wang via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 17 10:59:51 PDT 2018
Author: shuaiwang
Date: Mon Sep 17 10:59:51 2018
New Revision: 342403
URL: http://llvm.org/viewvc/llvm-project?rev=342403&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h
Modified: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp?rev=342403&r1=342402&r2=342403&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp Mon Sep 17 10:59:51 2018
@@ -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(c
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::storeOp
utils::IncludeSorter::toString(IncludeStyle));
}
+void UnnecessaryValueParamCheck::onEndOfTranslationUnit() {
+ MutationAnalyzers.clear();
+}
+
void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var,
const DeclRefExpr &CopyArgument,
const ASTContext &Context) {
Modified: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h?rev=342403&r1=342402&r2=342403&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.h Mon Sep 17 10:59:51 2018
@@ -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;
};
More information about the cfe-commits
mailing list