Skip to content

Commit 1c57143

Browse files
author
Adam Balogh
committed
[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
1 parent 2ef18fb commit 1c57143

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ loopEndingStmt(internal::Matcher<Stmt> Internal) {
2424
callExpr(Internal, callee(functionDecl(isNoReturn())))));
2525
}
2626

27-
/// \brief Return whether `S` is a reference to the declaration of `Var`.
27+
/// Return whether `S` is a reference to the declaration of `Var`.
2828
static bool isAccessForVar(const Stmt *S, const VarDecl *Var) {
2929
if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
3030
return DRE->getDecl() == Var;
3131

3232
return false;
3333
}
3434

35-
/// \brief Return whether `Var` has a pointer of reference in `S`.
35+
/// Return whether `Var` has a pointer or reference in `S`.
3636
static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
3737
if (const auto *DS = dyn_cast<DeclStmt>(S)) {
3838
for (const Decl *D : DS->getDeclGroup()) {
@@ -50,7 +50,7 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
5050
return false;
5151
}
5252

53-
/// \brief Return whether `Var` has a pointer of reference in `S`.
53+
/// Return whether `Var` has a pointer or reference in `S`.
5454
static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
5555
if (isPtrOrReferenceForVar(S, Var))
5656
return true;
@@ -66,13 +66,13 @@ static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
6666
return false;
6767
}
6868

69-
/// \brief Return whether `Var` has a pointer of reference in `Func`.
69+
/// Return whether `Var` has a pointer or reference in `Func`.
7070
static bool hasPtrOrReferenceInFunc(const FunctionDecl *Func,
7171
const VarDecl *Var) {
7272
return hasPtrOrReferenceInStmt(Func->getBody(), Var);
7373
}
7474

75-
/// \brief Return whether `Var` was changed in `LoopStmt`.
75+
/// Return whether `Var` was changed in `LoopStmt`.
7676
static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
7777
ASTContext *Context) {
7878
if (const auto *ForLoop = dyn_cast<ForStmt>(LoopStmt))
@@ -88,8 +88,7 @@ static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
8888
return ExprMutationAnalyzer(*LoopStmt, *Context).isMutated(Var);
8989
}
9090

91-
/// \brief Return whether `Cond` is a variable that is possibly changed in
92-
/// `LoopStmt`.
91+
/// Return whether `Cond` is a variable that is possibly changed in `LoopStmt`.
9392
static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
9493
const Stmt *LoopStmt, const Stmt *Cond,
9594
ASTContext *Context) {
@@ -116,7 +115,7 @@ static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
116115
return false;
117116
}
118117

119-
/// \brief Return whether at least one variable of `Cond` changed in `LoopStmt`.
118+
/// Return whether at least one variable of `Cond` changed in `LoopStmt`.
120119
static bool isAtLeastOneCondVarChanged(const FunctionDecl *Func,
121120
const Stmt *LoopStmt, const Stmt *Cond,
122121
ASTContext *Context) {
@@ -133,7 +132,7 @@ static bool isAtLeastOneCondVarChanged(const FunctionDecl *Func,
133132
return false;
134133
}
135134

136-
/// \brief Return the variable names in `Cond`.
135+
/// Return the variable names in `Cond`.
137136
static std::string getCondVarNames(const Stmt *Cond) {
138137
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
139138
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl()))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ considered infinite if it does not have any loop exit statement (``break``,
1515
the condition:
1616

1717
- It is a local variable.
18-
- It has no reference or pointer aliases
18+
- It has no reference or pointer aliases.
1919
- It is not a structure or class member.
2020

2121
Furthermore, the condition must not contain a function call to consider the loop

clang-tools-extra/test/clang-tidy/bugprone-infinite-loop.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ void escape_inside2() {
140140
} while (i < Limit);
141141
}
142142

143+
void escape_after1() {
144+
int i = 0;
145+
int j = 0;
146+
int Limit = 10;
147+
148+
while (i < Limit) {
149+
// False negative, but difficult to detect without CFG-based analysis
150+
}
151+
int *p = &i;
152+
}
153+
154+
void escape_after2() {
155+
int i = 0;
156+
int j = 0;
157+
int Limit = 10;
158+
159+
while (i < Limit) {
160+
// False negative, but difficult to detect without CFG-based analysis
161+
}
162+
int &ii = i;
163+
}
164+
-
165+
143166
int glob;
144167

145168
void global1(int &x) {

0 commit comments

Comments
 (0)