diff options
author | Adam Balogh <adam.balogh@ericsson.com> | 2019-10-02 07:14:11 +0000 |
---|---|---|
committer | Adam Balogh <adam.balogh@ericsson.com> | 2019-10-02 07:14:11 +0000 |
commit | 1c57143742b1deab32ac96cfd24c6b9dc9868a21 (patch) | |
tree | a5eb306758108b5e3f31d73996ac2782912ef3af | |
parent | 2ef18fb41aeb0e71744fd3e97cf25da49bdf6b64 (diff) | |
download | bcm5719-llvm-1c57143742b1deab32ac96cfd24c6b9dc9868a21.tar.gz bcm5719-llvm-1c57143742b1deab32ac96cfd24c6b9dc9868a21.zip |
[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
llvm-svn: 373428
3 files changed, 32 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp index d48a2c0a337..81ae45a0089 100644 --- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp @@ -24,7 +24,7 @@ loopEndingStmt(internal::Matcher<Stmt> Internal) { 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, const VarDecl *Var) { 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 Stmt *S, const VarDecl *Var) { 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(const Stmt *S, const VarDecl *Var) { 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 *LoopStmt, const VarDecl *Var, 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(const FunctionDecl *Func, 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(const FunctionDecl *Func, 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())) diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone-infinite-loop.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone-infinite-loop.rst index 6307afed475..89502c1882a 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone-infinite-loop.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone-infinite-loop.rst @@ -15,7 +15,7 @@ considered infinite if it does not have any loop exit statement (``break``, 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 diff --git a/clang-tools-extra/test/clang-tidy/bugprone-infinite-loop.cpp b/clang-tools-extra/test/clang-tidy/bugprone-infinite-loop.cpp index e6b85c19501..0ff82df2118 100644 --- a/clang-tools-extra/test/clang-tidy/bugprone-infinite-loop.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-infinite-loop.cpp @@ -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) { |