[clang] f85aedc - Make the ExprMutationAnalyzer explicit about how it traverses the AST

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Thu May 21 14:41:46 PDT 2020


Author: Stephen Kelly
Date: 2020-05-21T22:34:38+01:00
New Revision: f85aedc167cde76bdb47b7814f873cfb40ad3ed8

URL: https://github.com/llvm/llvm-project/commit/f85aedc167cde76bdb47b7814f873cfb40ad3ed8
DIFF: https://github.com/llvm/llvm-project/commit/f85aedc167cde76bdb47b7814f873cfb40ad3ed8.diff

LOG: Make the ExprMutationAnalyzer explicit about how it traverses the AST

Reviewers: aaron.ballman

Subscribers: baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72532

Added: 
    

Modified: 
    clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index b09be4317851..5e305534c812 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -280,13 +280,15 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const Expr *Exp) {
   const auto AsNonConstRefReturn = returnStmt(hasReturnValue(
                                                 maybeEvalCommaExpr(equalsNode(Exp))));
 
-  const auto Matches =
-      match(findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, AsNonConstThis,
-                               AsAmpersandOperand, AsPointerFromArrayDecay,
-                               AsOperatorArrowThis, AsNonConstRefArg,
-                               AsLambdaRefCaptureInit, AsNonConstRefReturn))
-                        .bind("stmt")),
-            Stm, Context);
+  const auto Matches = match(
+      traverse(
+          ast_type_traits::TK_AsIs,
+          findAll(stmt(anyOf(AsAssignmentLhs, AsIncDecOperand, AsNonConstThis,
+                             AsAmpersandOperand, AsPointerFromArrayDecay,
+                             AsOperatorArrowThis, AsNonConstRefArg,
+                             AsLambdaRefCaptureInit, AsNonConstRefReturn))
+                      .bind("stmt"))),
+      Stm, Context);
   return selectFirst<Stmt>("stmt", Matches);
 }
 
@@ -385,12 +387,15 @@ const Stmt *ExprMutationAnalyzer::findFunctionArgMutation(const Expr *Exp) {
   const auto IsInstantiated = hasDeclaration(isInstantiated());
   const auto FuncDecl = hasDeclaration(functionDecl().bind("func"));
   const auto Matches = match(
-      findAll(expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl,
+      traverse(
+          ast_type_traits::TK_AsIs,
+          findAll(
+              expr(anyOf(callExpr(NonConstRefParam, IsInstantiated, FuncDecl,
                                   unless(callee(namedDecl(hasAnyName(
                                       "::std::move", "::std::forward"))))),
                          cxxConstructExpr(NonConstRefParam, IsInstantiated,
                                           FuncDecl)))
-                  .bind(NodeID<Expr>::value)),
+                  .bind(NodeID<Expr>::value))),
       Stm, Context);
   for (const auto &Nodes : Matches) {
     const auto *Exp = Nodes.getNodeAs<Expr>(NodeID<Expr>::value);


        


More information about the cfe-commits mailing list