diff options
author | Shuai Wang <shuaiwang@google.com> | 2018-09-10 23:58:04 +0000 |
---|---|---|
committer | Shuai Wang <shuaiwang@google.com> | 2018-09-10 23:58:04 +0000 |
commit | cec7d3a055ede1655707c1c3a0b6fcc69c1569cf (patch) | |
tree | 86e2fc663f3d30c239a37b90fb1cab1364b96164 | |
parent | a80d6faa10d9b1562bb8d08506da8c69ff0b0ec6 (diff) | |
download | bcm5719-llvm-cec7d3a055ede1655707c1c3a0b6fcc69c1569cf.tar.gz bcm5719-llvm-cec7d3a055ede1655707c1c3a0b6fcc69c1569cf.zip |
Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer"
Summary:
Tests somehow break on windows (and only on windows)
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/13003
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/13747
I have yet figure out why so reverting to unbreak first.
Reviewers: george.karpenkov
Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits
Differential Revision: https://reviews.llvm.org/D51898
llvm-svn: 341886
-rw-r--r-- | clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp | 26 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp | 110 |
2 files changed, 10 insertions, 126 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp index f979e97a03d..adf4095d009 100644 --- a/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExprMutationAnalyzer.cpp @@ -145,16 +145,11 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) { hasUnaryOperand(equalsNode(Exp))); // Invoking non-const member function. - // A member function is assumed to be non-const when it is unresolved. const auto NonConstMethod = cxxMethodDecl(unless(isConst())); const auto AsNonConstThis = expr(anyOf(cxxMemberCallExpr(callee(NonConstMethod), on(equalsNode(Exp))), cxxOperatorCallExpr(callee(NonConstMethod), - hasArgument(0, equalsNode(Exp))), - callExpr(callee(expr(anyOf( - unresolvedMemberExpr(hasObjectExpression(equalsNode(Exp))), - cxxDependentScopeMemberExpr( - hasObjectExpression(equalsNode(Exp))))))))); + hasArgument(0, equalsNode(Exp))))); // Taking address of 'Exp'. // We're assuming 'Exp' is mutated as soon as its address is taken, though in @@ -170,16 +165,10 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) { unless(hasParent(arraySubscriptExpr())), has(equalsNode(Exp))); // Used as non-const-ref argument when calling a function. - // An argument is assumed to be non-const-ref when the function is unresolved. const auto NonConstRefParam = forEachArgumentWithParam( equalsNode(Exp), parmVarDecl(hasType(nonConstReferenceType()))); - const auto AsNonConstRefArg = anyOf( - callExpr(NonConstRefParam), cxxConstructExpr(NonConstRefParam), - callExpr(callee(expr(anyOf(unresolvedLookupExpr(), unresolvedMemberExpr(), - cxxDependentScopeMemberExpr(), - hasType(templateTypeParmType())))), - hasAnyArgument(equalsNode(Exp))), - cxxUnresolvedConstructExpr(hasAnyArgument(equalsNode(Exp)))); + const auto AsNonConstRefArg = + anyOf(callExpr(NonConstRefParam), cxxConstructExpr(NonConstRefParam)); // Captured by a lambda by reference. // If we're initializing a capture with 'Exp' directly then we're initializing @@ -206,12 +195,9 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) { const Stmt *ExprMutationAnalyzer::findMemberMutation(const Expr *Exp) { // Check whether any member of 'Exp' is mutated. - const auto MemberExprs = - match(findAll(expr(anyOf(memberExpr(hasObjectExpression(equalsNode(Exp))), - cxxDependentScopeMemberExpr( - hasObjectExpression(equalsNode(Exp))))) - .bind("expr")), - Stm, Context); + const auto MemberExprs = match( + findAll(memberExpr(hasObjectExpression(equalsNode(Exp))).bind("expr")), + Stm, Context); return findExprMutation(MemberExprs); } diff --git a/clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp b/clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp index 013493ef2c0..9d0728bf9c1 100644 --- a/clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp @@ -114,26 +114,6 @@ TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) { EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()")); } -TEST(ExprMutationAnalyzerTest, AssumedNonConstMemberFunc) { - auto AST = tooling::buildASTFromCode( - "struct X { template <class T> void mf(); };" - "template <class T> void f() { X x; x.mf<T>(); }"); - auto Results = - match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf<T>()")); - - AST = - tooling::buildASTFromCode("template <class T> void f() { T x; x.mf(); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()")); - - AST = tooling::buildASTFromCode( - "template <class T> struct X;" - "template <class T> void f() { X<T> x; x.mf(); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()")); -} - TEST(ExprMutationAnalyzerTest, ConstMemberFunc) { const auto AST = tooling::buildASTFromCode( "void f() { struct Foo { void mf() const; }; Foo x; x.mf(); }"); @@ -312,51 +292,6 @@ TEST(ExprMutationAnalyzerTest, Forward) { ElementsAre("std::forward<A &>(x)")); } -TEST(ExprMutationAnalyzerTest, CallUnresolved) { - auto AST = - tooling::buildASTFromCode("template <class T> void f() { T x; g(x); }"); - auto Results = - match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - - AST = tooling::buildASTFromCode( - "template <int N> void f() { char x[N]; g(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - - AST = tooling::buildASTFromCode( - "template <class T> void f(T t) { int x; g(t, x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(t, x)")); - - AST = tooling::buildASTFromCode( - "template <class T> void f(T t) { int x; t.mf(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("t.mf(x)")); - - AST = tooling::buildASTFromCode( - "template <class T> struct S;" - "template <class T> void f() { S<T> s; int x; s.mf(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("s.mf(x)")); - - AST = tooling::buildASTFromCode( - "struct S { template <class T> void mf(); };" - "template <class T> void f(S s) { int x; s.mf<T>(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("s.mf<T>(x)")); - - AST = tooling::buildASTFromCode("template <class F>" - "void g(F f) { int x; f(x); } "); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("f(x)")); - - AST = tooling::buildASTFromCode( - "template <class T> void f() { int x; (void)T(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("T(x)")); -} - TEST(ExprMutationAnalyzerTest, ReturnAsValue) { const auto AST = tooling::buildASTFromCode("int f() { int x; return x; }"); const auto Results = @@ -412,21 +347,6 @@ TEST(ExprMutationAnalyzerTest, ArrayToPointerDecay) { EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); } -TEST(ExprMutationAnalyzerTest, TemplateWithArrayToPointerDecay) { - const auto AST = tooling::buildASTFromCode( - "template <typename T> struct S { static constexpr int v = 8; };" - "template <> struct S<int> { static constexpr int v = 4; };" - "void g(char*);" - "template <typename T> void f() { char x[S<T>::v]; g(x); }" - "template <> void f<int>() { char y[S<int>::v]; g(y); }"); - const auto ResultsX = - match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(ResultsX, AST.get()), ElementsAre("g(x)")); - const auto ResultsY = - match(withEnclosingCompound(declRefTo("y")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(ResultsY, AST.get()), ElementsAre("y")); -} - TEST(ExprMutationAnalyzerTest, FollowRefModified) { const auto AST = tooling::buildASTFromCode( "void f() { int x; int& r0 = x; int& r1 = r0; int& r2 = r1; " @@ -478,43 +398,21 @@ TEST(ExprMutationAnalyzerTest, ArrayElementNotModified) { } TEST(ExprMutationAnalyzerTest, NestedMemberModified) { - auto AST = tooling::buildASTFromCode( + const auto AST = tooling::buildASTFromCode( "void f() { struct A { int vi; }; struct B { A va; }; " "struct C { B vb; }; C x; x.vb.va.vi = 10; }"); - auto Results = + const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.vb.va.vi = 10")); - - AST = tooling::buildASTFromCode( - "template <class T> void f() { T x; x.y.z = 10; }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.y.z = 10")); - - AST = tooling::buildASTFromCode( - "template <class T> struct S;" - "template <class T> void f() { S<T> x; x.y.z = 10; }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.y.z = 10")); } TEST(ExprMutationAnalyzerTest, NestedMemberNotModified) { - auto AST = tooling::buildASTFromCode( + const auto AST = tooling::buildASTFromCode( "void f() { struct A { int vi; }; struct B { A va; }; " "struct C { B vb; }; C x; x.vb.va.vi; }"); - auto Results = + const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - - AST = - tooling::buildASTFromCode("template <class T> void f() { T x; x.y.z; }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_FALSE(isMutated(Results, AST.get())); - - AST = tooling::buildASTFromCode( - "template <class T> struct S;" - "template <class T> void f() { S<T> x; x.y.z; }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, CastToValue) { |