Skip to content

Commit d94c7bf

Browse files
committed
[clang-tidy] Fix a potential infinite loop in readability-isolate-declaration check.
Reviewers: ilya-biryukov Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67654 llvm-svn: 372206
1 parent d97865e commit d94c7bf

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang-tools-extra/clang-tidy/utils/LexerUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
1111

1212
#include "clang/AST/ASTContext.h"
13+
#include "clang/Basic/TokenKinds.h"
1314
#include "clang/Lex/Lexer.h"
1415

1516
namespace clang {
@@ -70,6 +71,11 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start,
7071
if (PotentialMatch.isOneOf(TK, TKs...))
7172
return PotentialMatch.getLocation();
7273

74+
// If we reach the end of the file, and eof is not the target token, we stop
75+
// the loop, otherwise we will get infinite loop (findNextToken will return
76+
// eof on eof).
77+
if (PotentialMatch.is(tok::eof))
78+
return SourceLocation();
7379
Start = PotentialMatch.getLastLoc();
7480
}
7581
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-isolate-declaration %t
2+
3+
int main(){
4+
int a, b
5+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
6+
// CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-diagnostic-error]
7+
}

0 commit comments

Comments
 (0)