[clang-tools-extra] r248895 - [clang-tidy] Fix an assertion in the readability-braces-around-statements check.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 05:48:42 PDT 2015


Author: alexfh
Date: Wed Sep 30 07:48:42 2015
New Revision: 248895

URL: http://llvm.org/viewvc/llvm-project?rev=248895&view=rev
Log:
[clang-tidy] Fix an assertion in the readability-braces-around-statements check.

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=248895&r1=248894&r2=248895&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Wed Sep 30 07:48:42 2015
@@ -232,8 +232,18 @@ bool BracesAroundStatementsCheck::checkS
 
   // 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;

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp?rev=248895&r1=248894&r2=248895&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp Wed Sep 30 07:48:42 2015
@@ -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: {{^}$}}
 }




More information about the cfe-commits mailing list