[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:
parent
cb843f5b55
commit
e31fe508e8
|
@ -81,6 +81,10 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
|
||||||
SourceLocation InnerLoc = Inner->getBeginLoc();
|
SourceLocation InnerLoc = Inner->getBeginLoc();
|
||||||
SourceLocation OuterLoc = CurrentStmt->getBeginLoc();
|
SourceLocation OuterLoc = CurrentStmt->getBeginLoc();
|
||||||
|
|
||||||
|
if (InnerLoc.isInvalid() || InnerLoc.isMacroID() || OuterLoc.isInvalid() ||
|
||||||
|
OuterLoc.isMacroID())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (SM.getExpansionLineNumber(InnerLoc) ==
|
if (SM.getExpansionLineNumber(InnerLoc) ==
|
||||||
SM.getExpansionLineNumber(OuterLoc))
|
SM.getExpansionLineNumber(OuterLoc))
|
||||||
continue;
|
continue;
|
||||||
|
@ -88,7 +92,7 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
|
||||||
const Stmt *NextStmt = CStmt->body_begin()[i + 1];
|
const Stmt *NextStmt = CStmt->body_begin()[i + 1];
|
||||||
SourceLocation NextLoc = NextStmt->getBeginLoc();
|
SourceLocation NextLoc = NextStmt->getBeginLoc();
|
||||||
|
|
||||||
if (InnerLoc.isMacroID() || OuterLoc.isMacroID() || NextLoc.isMacroID())
|
if (NextLoc.isInvalid() || NextLoc.isMacroID())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (SM.getExpansionColumnNumber(InnerLoc) ==
|
if (SM.getExpansionColumnNumber(InnerLoc) ==
|
||||||
|
|
|
@ -8,7 +8,7 @@ void foo2();
|
||||||
foo1(); \
|
foo1(); \
|
||||||
foo2();
|
foo2();
|
||||||
|
|
||||||
int main()
|
void f()
|
||||||
{
|
{
|
||||||
bool cond1 = true;
|
bool cond1 = true;
|
||||||
bool cond2 = true;
|
bool cond2 = true;
|
||||||
|
@ -109,3 +109,12 @@ int main()
|
||||||
|
|
||||||
BLOCK
|
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) {}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue