aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/utils
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/utils
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/utils')
-rw-r--r--clang-tidy/utils/ExprMutationAnalyzer.cpp16
-rw-r--r--clang-tidy/utils/ExprMutationAnalyzer.h6
2 files changed, 11 insertions, 11 deletions
diff --git a/clang-tidy/utils/ExprMutationAnalyzer.cpp b/clang-tidy/utils/ExprMutationAnalyzer.cpp
index f1cd1daf..f979e97a 100644
--- a/clang-tidy/utils/ExprMutationAnalyzer.cpp
+++ b/clang-tidy/utils/ExprMutationAnalyzer.cpp
@@ -102,7 +102,7 @@ bool ExprMutationAnalyzer::isUnevaluated(const Expr *Exp) {
hasDescendant(equalsNode(Exp)))),
cxxNoexceptExpr())))))
.bind("expr")),
- *Stm, *Context)) != nullptr;
+ Stm, Context)) != nullptr;
}
const Stmt *
@@ -125,7 +125,7 @@ ExprMutationAnalyzer::findDeclMutation(ArrayRef<BoundNodes> Matches) {
const Stmt *ExprMutationAnalyzer::findDeclMutation(const Decl *Dec) {
const auto Refs = match(
- findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), *Stm, *Context);
+ findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), Stm, Context);
for (const auto &RefNodes : Refs) {
const auto *E = RefNodes.getNodeAs<Expr>("expr");
if (findMutation(E))
@@ -200,7 +200,7 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
AsNonConstRefArg, AsLambdaRefCaptureInit,
AsNonConstRefReturn))
.bind("stmt")),
- *Stm, *Context);
+ Stm, Context);
return selectFirst<Stmt>("stmt", Matches);
}
@@ -211,7 +211,7 @@ const Stmt *ExprMutationAnalyzer::findMemberMutation(const Expr *Exp) {
cxxDependentScopeMemberExpr(
hasObjectExpression(equalsNode(Exp)))))
.bind("expr")),
- *Stm, *Context);
+ Stm, Context);
return findExprMutation(MemberExprs);
}
@@ -220,7 +220,7 @@ const Stmt *ExprMutationAnalyzer::findArrayElementMutation(const Expr *Exp) {
const auto SubscriptExprs = match(
findAll(arraySubscriptExpr(hasBase(ignoringImpCasts(equalsNode(Exp))))
.bind("expr")),
- *Stm, *Context);
+ Stm, Context);
return findExprMutation(SubscriptExprs);
}
@@ -233,7 +233,7 @@ const Stmt *ExprMutationAnalyzer::findCastMutation(const Expr *Exp) {
implicitCastExpr(hasImplicitDestinationType(
nonConstReferenceType()))))
.bind("expr")),
- *Stm, *Context);
+ Stm, Context);
return findExprMutation(Casts);
}
@@ -245,7 +245,7 @@ const Stmt *ExprMutationAnalyzer::findRangeLoopMutation(const Expr *Exp) {
hasLoopVariable(
varDecl(hasType(nonConstReferenceType())).bind("decl")),
hasRangeInit(equalsNode(Exp)))),
- *Stm, *Context);
+ Stm, Context);
return findDeclMutation(LoopVars);
}
@@ -265,7 +265,7 @@ const Stmt *ExprMutationAnalyzer::findReferenceMutation(const Expr *Exp) {
unless(hasParent(declStmt(hasParent(
cxxForRangeStmt(hasRangeStmt(equalsBoundNode("stmt"))))))))
.bind("decl"))),
- *Stm, *Context);
+ Stm, Context);
return findDeclMutation(Refs);
}
diff --git a/clang-tidy/utils/ExprMutationAnalyzer.h b/clang-tidy/utils/ExprMutationAnalyzer.h
index 256bb712..e295de9b 100644
--- a/clang-tidy/utils/ExprMutationAnalyzer.h
+++ b/clang-tidy/utils/ExprMutationAnalyzer.h
@@ -23,7 +23,7 @@ namespace utils {
/// a given statement.
class ExprMutationAnalyzer {
public:
- ExprMutationAnalyzer(const Stmt *Stm, ASTContext *Context)
+ ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
: Stm(Stm), Context(Context) {}
bool isMutated(const Decl *Dec) { return findDeclMutation(Dec) != nullptr; }
@@ -44,8 +44,8 @@ private:
const Stmt *findRangeLoopMutation(const Expr *Exp);
const Stmt *findReferenceMutation(const Expr *Exp);
- const Stmt *const Stm;
- ASTContext *const Context;
+ const Stmt &Stm;
+ ASTContext &Context;
llvm::DenseMap<const Expr *, const Stmt *> Results;
};