[PATCH] D40937: [clang-tidy] Infinite loop checker

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 7 08:08:24 PST 2017


xazax.hun added a comment.

This does not support memberExprs as condition variables right now.

What happens if you have something like this:

  struct X {
  void f(int a) {
    while(a < i) {
      --i;
    } 
  }
  int i;
  };

I think you could extend the test cases with some classes.



================
Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:28
+void InfiniteLoopCheck::registerMatchers(MatchFinder *Finder) {
+  const auto loopCondition = []() {
+    return allOf(hasCondition(expr().bind("condition")),
----------------
Do you need this to be a lambda? Can't you just use a local variable?


================
Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:31
+                 anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
+                       hasAncestor(functionDecl().bind("containing-func"))),
+                 unless(hasBody(hasDescendant(loopEndingStmt()))));
----------------
Maybe this is not too important, but you might also want to check for blocks here.


================
Comment at: clang-tidy/misc/InfiniteLoopCheck.cpp:48
+                        declRefExpr(to(varDecl(VarNodeMatcher)))))),
+      binaryOperator(anyOf(hasOperatorName("="), hasOperatorName("+="),
+                           hasOperatorName("/="), hasOperatorName("*="),
----------------
This can be greatly simplified once https://reviews.llvm.org/D38921 is accepted. Maybe you could use that as a dependent revision? It should be close to be accepted.


https://reviews.llvm.org/D40937





More information about the cfe-commits mailing list