[PATCH] D15797: [clang-tidy] Fix readability-braces-around-statements assert failure

Matt Stancliff via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 29 10:32:45 PST 2015


mattsta updated this revision to Diff 43748.
mattsta added a comment.

Updated to include fix for:

  Assertion failed: (InitialLoc.isValid()), function checkStmt, file ../llvm/tools/clang/tools/extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp, line 226.


Repository:
  rL LLVM

http://reviews.llvm.org/D15797

Files:
  BracesAroundStatementsCheck.cpp

Index: BracesAroundStatementsCheck.cpp
===================================================================
--- BracesAroundStatementsCheck.cpp
+++ BracesAroundStatementsCheck.cpp
@@ -143,14 +143,14 @@
   } else if (auto S = Result.Nodes.getNodeAs<DoStmt>("do")) {
     checkStmt(Result, S->getBody(), S->getDoLoc(), S->getWhileLoc());
   } else if (auto S = Result.Nodes.getNodeAs<WhileStmt>("while")) {
-    SourceLocation StartLoc = findRParenLoc(S, SM, Context);
-    if (StartLoc.isInvalid())
+    if (S->getCond()->getLocStart().isInvalid())
       return;
+    SourceLocation StartLoc = findRParenLoc(S, SM, Context);
     checkStmt(Result, S->getBody(), StartLoc);
   } else if (auto S = Result.Nodes.getNodeAs<IfStmt>("if")) {
-    SourceLocation StartLoc = findRParenLoc(S, SM, Context);
-    if (StartLoc.isInvalid())
+    if (S->getCond()->getLocStart().isInvalid())
       return;
+    SourceLocation StartLoc = findRParenLoc(S, SM, Context);
     if (ForceBracesStmts.erase(S))
       ForceBracesStmts.insert(S->getThen());
     bool BracedIf = checkStmt(Result, S->getThen(), StartLoc, S->getElseLoc());
@@ -219,7 +219,7 @@
   CharSourceRange FileRange = Lexer::makeFileCharRange(
       CharSourceRange::getTokenRange(S->getSourceRange()), SM,
       Context->getLangOpts());
-  if (FileRange.isInvalid())
+  if (FileRange.isInvalid() || InitialLoc.isInvalid())
     return false;
 
   // InitialLoc points at the last token before opening brace to be inserted.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15797.43748.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151229/34ebab22/attachment.bin>


More information about the cfe-commits mailing list