[clang-tools-extra] r373428 - [clang-tidy] Fix for commits rL372706 and rL372711

Adam Balogh via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 00:14:11 PDT 2019


Author: baloghadamsoftware
Date: Wed Oct  2 00:14:11 2019
New Revision: 373428

URL: http://llvm.org/viewvc/llvm-project?rev=373428&view=rev
Log:
[clang-tidy] Fix for commits rL372706 and rL372711

The patch committed was not the accepted version but the
previous one. This commit fixes this issue.

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


Modified:
    clang-tools-extra/trunk/clang-tidy/bugprone/InfiniteLoopCheck.cpp
    clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst
    clang-tools-extra/trunk/test/clang-tidy/bugprone-infinite-loop.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/InfiniteLoopCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/InfiniteLoopCheck.cpp?rev=373428&r1=373427&r2=373428&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/InfiniteLoopCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/InfiniteLoopCheck.cpp Wed Oct  2 00:14:11 2019
@@ -24,7 +24,7 @@ loopEndingStmt(internal::Matcher<Stmt> I
                     callExpr(Internal, callee(functionDecl(isNoReturn())))));
 }
 
-/// \brief Return whether `S` is a reference to the declaration of `Var`.
+/// Return whether `S` is a reference to the declaration of `Var`.
 static bool isAccessForVar(const Stmt *S, const VarDecl *Var) {
   if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
     return DRE->getDecl() == Var;
@@ -32,7 +32,7 @@ static bool isAccessForVar(const Stmt *S
   return false;
 }
 
-/// \brief Return whether `Var` has a pointer of reference in `S`.
+/// Return whether `Var` has a pointer or reference in `S`.
 static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
   if (const auto *DS = dyn_cast<DeclStmt>(S)) {
     for (const Decl *D : DS->getDeclGroup()) {
@@ -50,7 +50,7 @@ static bool isPtrOrReferenceForVar(const
   return false;
 }
 
-/// \brief Return whether `Var` has a pointer of reference in `S`.
+/// Return whether `Var` has a pointer or reference in `S`.
 static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
   if (isPtrOrReferenceForVar(S, Var))
     return true;
@@ -66,13 +66,13 @@ static bool hasPtrOrReferenceInStmt(cons
   return false;
 }
 
-/// \brief Return whether `Var` has a pointer of reference in `Func`.
+/// Return whether `Var` has a pointer or reference in `Func`.
 static bool hasPtrOrReferenceInFunc(const FunctionDecl *Func,
                                     const VarDecl *Var) {
   return hasPtrOrReferenceInStmt(Func->getBody(), Var);
 }
 
-/// \brief Return whether `Var` was changed in `LoopStmt`.
+/// Return whether `Var` was changed in `LoopStmt`.
 static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
                       ASTContext *Context) {
   if (const auto *ForLoop = dyn_cast<ForStmt>(LoopStmt))
@@ -88,8 +88,7 @@ static bool isChanged(const Stmt *LoopSt
   return ExprMutationAnalyzer(*LoopStmt, *Context).isMutated(Var);
 }
 
-/// \brief Return whether `Cond` is a variable that is possibly changed in
-/// `LoopStmt`.
+/// Return whether `Cond` is a variable that is possibly changed in `LoopStmt`.
 static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
                                        const Stmt *LoopStmt, const Stmt *Cond,
                                        ASTContext *Context) {
@@ -116,7 +115,7 @@ static bool isVarThatIsPossiblyChanged(c
   return false;
 }
 
-/// \brief Return whether at least one variable of `Cond` changed in `LoopStmt`.
+/// Return whether at least one variable of `Cond` changed in `LoopStmt`.
 static bool isAtLeastOneCondVarChanged(const FunctionDecl *Func,
                                        const Stmt *LoopStmt, const Stmt *Cond,
                                        ASTContext *Context) {
@@ -133,7 +132,7 @@ static bool isAtLeastOneCondVarChanged(c
   return false;
 }
 
-/// \brief Return the variable names in `Cond`.
+/// Return the variable names in `Cond`.
 static std::string getCondVarNames(const Stmt *Cond) {
   if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
     if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl()))

Modified: 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=373428&r1=373427&r2=373428&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-infinite-loop.rst Wed Oct  2 00:14:11 2019
@@ -15,7 +15,7 @@ considered infinite if it does not have
 the condition:
 
 - It is a local variable.
-- It has no reference or pointer aliases
+- 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

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-infinite-loop.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-infinite-loop.cpp?rev=373428&r1=373427&r2=373428&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-infinite-loop.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-infinite-loop.cpp Wed Oct  2 00:14:11 2019
@@ -140,6 +140,29 @@ void escape_inside2() {
   } while (i < Limit);
 }
 
+void escape_after1() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+    // False negative, but difficult to detect without CFG-based analysis
+  }
+  int *p = &i;
+}
+
+void escape_after2() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+    // False negative, but difficult to detect without CFG-based analysis
+  }
+  int &ii = i;
+}
+-
+
 int glob;
 
 void global1(int &x) {




More information about the cfe-commits mailing list