[clang-tools-extra] r372711 - [clang-tidy] Add bugprone-infinite-loop.rst from D64736 to fix buildbot

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 24 02:32:00 PDT 2019


Author: maskray
Date: Tue Sep 24 02:32:00 2019
New Revision: 372711

URL: http://llvm.org/viewvc/llvm-project?rev=372711&view=rev
Log:
[clang-tidy] Add bugprone-infinite-loop.rst from D64736 to fix buildbot

Added:
    clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst

Added: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst?rev=372711&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst (added)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst Tue Sep 24 02:32:00 2019
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - bugprone-infinite-loop
+
+bugprone-infinite-loop
+======================
+
+Finds obvious infinite loops (loops where the condition variable is not changed
+at all).
+
+Finding infinite loops is well-known to be impossible (halting problem).
+However, it is possible to detect some obvious infinite loops, for example, if
+the loop condition is not changed. This check detects such loops. A loop is
+considered infinite if it does not have any loop exit statement (``break``,
+``continue``, ``goto``, ``return``, ``throw`` or a call to a function called as
+``[[noreturn]]``) and all of the following conditions hold for every variable in
+the condition:
+
+- It is a local variable.
+- It has no reference or pointer aliases
+- It is not a structure or class member.
+
+Furthermore, the condition must not contain a function call to consider the loop
+infinite since functions may return different values for different calls.
+
+For example, the following loop is considered infinite `i` is not changed in
+the body:
+
+.. code-block:: c++
+
+  int i = 0, j = 0;
+  while (i < 10) {
+    ++j;
+  }




More information about the cfe-commits mailing list