Index: BracesAroundStatementsCheck.cpp =================================================================== --- BracesAroundStatementsCheck.cpp +++ BracesAroundStatementsCheck.cpp @@ -143,14 +143,14 @@ } else if (auto S = Result.Nodes.getNodeAs("do")) { checkStmt(Result, S->getBody(), S->getDoLoc(), S->getWhileLoc()); } else if (auto S = Result.Nodes.getNodeAs("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("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.