[clang-tools-extra] r372206 - [clang-tidy] Fix a potential infinite loop in readability-isolate-declaration check.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 18 02:21:35 PDT 2019
Author: hokein
Date: Wed Sep 18 02:21:35 2019
New Revision: 372206
URL: http://llvm.org/viewvc/llvm-project?rev=372206&view=rev
Log:
[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
Added:
clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h
Modified: clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h?rev=372206&r1=372205&r2=372206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/LexerUtils.h Wed Sep 18 02:21:35 2019
@@ -10,6 +10,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
#include "clang/AST/ASTContext.h"
+#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/Lexer.h"
namespace clang {
@@ -70,6 +71,11 @@ SourceLocation findNextAnyTokenKind(Sour
if (PotentialMatch.isOneOf(TK, TKs...))
return PotentialMatch.getLocation();
+ // If we reach the end of the file, and eof is not the target token, we stop
+ // the loop, otherwise we will get infinite loop (findNextToken will return
+ // eof on eof).
+ if (PotentialMatch.is(tok::eof))
+ return SourceLocation();
Start = PotentialMatch.getLastLoc();
}
}
Added: clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp?rev=372206&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp Wed Sep 18 02:21:35 2019
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-isolate-declaration %t
+
+int main(){
+ int a, b
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+ // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-diagnostic-error]
+}
More information about the cfe-commits
mailing list