diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-09-30 12:48:42 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-09-30 12:48:42 +0000 |
commit | 08023c696da5f6f380cbbc3d1db160dfd5975e54 (patch) | |
tree | 913320fbfc263f4676ec4e39d659b1631df11659 | |
parent | 3c412e14cc532c4ee068fe8abf0ad7d750e11cdb (diff) | |
download | bcm5719-llvm-08023c696da5f6f380cbbc3d1db160dfd5975e54.tar.gz bcm5719-llvm-08023c696da5f6f380cbbc3d1db160dfd5975e54.zip |
[clang-tidy] Fix an assertion in the readability-braces-around-statements check.
llvm-svn: 248895
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | 10 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp | 8 |
2 files changed, 18 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index d6548fc7d99..a9d11990c44 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -232,8 +232,18 @@ bool BracesAroundStatementsCheck::checkStmt( // InitialLoc points at the last token before opening brace to be inserted. assert(InitialLoc.isValid()); + // Convert InitialLoc to file location, if it's on the same macro expansion + // level as the start of the statement. We also need file locations for + // Lexer::getLocForEndOfToken working properly. + InitialLoc = Lexer::makeFileCharRange( + CharSourceRange::getCharRange(InitialLoc, S->getLocStart()), + SM, Context->getLangOpts()) + .getBegin(); + if (InitialLoc.isInvalid()) + return false; SourceLocation StartLoc = Lexer::getLocForEndOfToken(InitialLoc, 0, SM, Context->getLangOpts()); + // StartLoc points at the location of the opening brace to be inserted. SourceLocation EndLoc; std::string ClosingInsertion; diff --git a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp index 0f0b76548d0..485a13a6827 100644 --- a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp @@ -183,4 +183,12 @@ int test_macros(bool b) { // CHECK-FIXES: } else { // CHECK-FIXES-NEXT: M(return 2); // CHECK-FIXES-NEXT: } + M( + for (;;) + ; + ); + // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: statement should be inside braces + // CHECK-FIXES: {{^}} for (;;) {{{$}} + // CHECK-FIXES-NEXT: {{^ ;$}} + // CHECK-FIXES-NEXT: {{^}$}} } |