[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()

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@358589 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clang-tidy/readability/MisleadingIndentationCheck.cpp b/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 767406e..0fd5c1f 100644
--- a/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -81,6 +81,10 @@
     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 @@
     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) ==
diff --git a/test/clang-tidy/readability-misleading-indentation.cpp b/test/clang-tidy/readability-misleading-indentation.cpp
index 59d5f40..4039949 100644
--- a/test/clang-tidy/readability-misleading-indentation.cpp
+++ b/test/clang-tidy/readability-misleading-indentation.cpp
@@ -8,7 +8,7 @@
     foo1();   \
     foo2();
 
-int main()
+void f()
 {
   bool cond1 = true;
   bool cond2 = true;
@@ -90,7 +90,7 @@
        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 @@
 
   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) {}
+}