[PATCH] D52158: [clang-tidy] Remove duplicated logic in UnnecessaryValueParamCheck and use FunctionParmMutationAnalyzer instead.
Shuai Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 16 15:59:15 PDT 2018
shuaiwang created this revision.
shuaiwang added reviewers: alexfh, JonasToth.
Herald added subscribers: cfe-commits, Szelethus, a.sidorin, chrib, kristof.beyls, xazax.hun.
Herald added a reviewer: george.karpenkov.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D52158
Files:
clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tidy/performance/UnnecessaryValueParamCheck.h
Index: clang-tidy/performance/UnnecessaryValueParamCheck.h
===================================================================
--- clang-tidy/performance/UnnecessaryValueParamCheck.h
+++ 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 @@
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;
};
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===================================================================
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ 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 @@
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 @@
utils::IncludeSorter::toString(IncludeStyle));
}
+void UnnecessaryValueParamCheck::onEndOfTranslationUnit() {
+ MutationAnalyzers.clear();
+}
+
void UnnecessaryValueParamCheck::handleMoveFix(const ParmVarDecl &Var,
const DeclRefExpr &CopyArgument,
const ASTContext &Context) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52158.165703.patch
Type: text/x-patch
Size: 3108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180916/764b5f4b/attachment.bin>
More information about the cfe-commits
mailing list