aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/performance
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-09-10 19:59:18 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-09-10 19:59:18 +0000
commite8f226ac6aadac6d149ade141390052dcbac2701 (patch)
tree949e12b287b7cd98f107303831287ade48613f62 /clang-tidy/performance
parentd204c088c7d8f6892bb0145794dd243f8c91ea96 (diff)
[clang-tidy] ExprMutationAnalyzer: construct from references. Fixes PR38888
Summary: I have hit this the rough way, while trying to use this in D51870. There is no particular point in storing the pointers, and moreover the pointers are assumed to be non-null, and that assumption is not enforced. If they are null, it won't be able to do anything good with them anyway. Initially i thought about simply adding asserts() that they are not null, but taking/storing references looks like even cleaner solution? Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38888 | PR38888 ]] Reviewers: JonasToth, shuaiwang, alexfh, george.karpenkov Reviewed By: shuaiwang Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D51884 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@341854 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/performance')
-rw-r--r--clang-tidy/performance/ForRangeCopyCheck.cpp4
-rw-r--r--clang-tidy/performance/UnnecessaryValueParamCheck.cpp4
2 files changed, 4 insertions, 4 deletions
diff --git a/clang-tidy/performance/ForRangeCopyCheck.cpp b/clang-tidy/performance/ForRangeCopyCheck.cpp
index 867d95d8..0a3cc4f6 100644
--- a/clang-tidy/performance/ForRangeCopyCheck.cpp
+++ b/clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -88,8 +88,8 @@ bool ForRangeCopyCheck::handleCopyIsOnlyConstReferenced(
// Because the fix (changing to `const auto &`) will introduce an unused
// compiler warning which can't be suppressed.
// Since this case is very rare, it is safe to ignore it.
- if (!utils::ExprMutationAnalyzer(ForRange.getBody(), &Context)
- .isMutated(&LoopVar) &&
+ if (!utils::ExprMutationAnalyzer(*ForRange.getBody(), Context)
+ .isMutated(&LoopVar) &&
!utils::decl_ref_expr::allDeclRefExprs(LoopVar, *ForRange.getBody(),
Context)
.empty()) {
diff --git a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index 8c9259c7..63b853de 100644
--- a/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -95,14 +95,14 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
// 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 (utils::ExprMutationAnalyzer(Function->getBody(), Result.Context)
+ if (utils::ExprMutationAnalyzer(*Function->getBody(), *Result.Context)
.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 (utils::ExprMutationAnalyzer(Init->getInit(), Result.Context)
+ if (utils::ExprMutationAnalyzer(*Init->getInit(), *Result.Context)
.isMutated(Param))
return;
}