[clang-tidy] Fix invalid location in readability-misleading-indentation diagnostic

Before this patch readability-misleading-indentation could issue diagnostics
with an invalid location, which would lead to an assertion failure in
ClangTidyContext::diag()

llvm-svn: 358589
This commit is contained in:
Alexander Kornienko 2019-04-17 16:19:47 +00:00
parent cb843f5b55
commit e31fe508e8
2 changed files with 16 additions and 3 deletions

View File

@ -81,6 +81,10 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
SourceLocation InnerLoc = Inner->getBeginLoc();
SourceLocation OuterLoc = CurrentStmt->getBeginLoc();
if (InnerLoc.isInvalid() || InnerLoc.isMacroID() || OuterLoc.isInvalid() ||
OuterLoc.isMacroID())
continue;
if (SM.getExpansionLineNumber(InnerLoc) ==
SM.getExpansionLineNumber(OuterLoc))
continue;
@ -88,7 +92,7 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
const Stmt *NextStmt = CStmt->body_begin()[i + 1];
SourceLocation NextLoc = NextStmt->getBeginLoc();
if (InnerLoc.isMacroID() || OuterLoc.isMacroID() || NextLoc.isMacroID())
if (NextLoc.isInvalid() || NextLoc.isMacroID())
continue;
if (SM.getExpansionColumnNumber(InnerLoc) ==

View File

@ -8,7 +8,7 @@ void foo2();
foo1(); \
foo2();
int main()
void f()
{
bool cond1 = true;
bool cond2 = true;
@ -90,7 +90,7 @@ int main()
else {
}
// CHECK-MESSAGES: :[[@LINE-2]]:8: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
if (cond1) {
if (cond1) {
}
@ -109,3 +109,12 @@ int main()
BLOCK
}
void g(bool x) {
if (x)
#pragma unroll
for (int k = 0; k < 1; ++k) {}
#pragma unroll
for (int k = 0; k < 1; ++k) {}
}