[Diagnostic] make Wmisleading-indendation not warn about labels
authorTyker <tyker1@outlook.com>
Mon, 6 Jan 2020 21:04:55 +0000 (22:04 +0100)
committerTyker <tyker1@outlook.com>
Mon, 6 Jan 2020 22:22:27 +0000 (23:22 +0100)
Reviewers: aaron.ballman, xbolva00

Reviewed By: aaron.ballman

Subscribers: nickdesaulniers, nathanchance

Differential Revision: https://reviews.llvm.org/D72202

clang/lib/Parse/ParseStmt.cpp
clang/test/Parser/warn-misleading-indentation.cpp

index b796540..0339328 100644 (file)
@@ -1272,10 +1272,12 @@ struct MisleadingIndentationChecker {
 
     if (PrevColNum != 0 && CurColNum != 0 && StmtColNum != 0 &&
         ((PrevColNum > StmtColNum && PrevColNum == CurColNum) ||
-         !Tok.isAtStartOfLine()) && SM.getPresumedLineNumber(StmtLoc) !=
-          SM.getPresumedLineNumber(Tok.getLocation())) {
-      P.Diag(Tok.getLocation(), diag::warn_misleading_indentation)
-          << Kind;
+         !Tok.isAtStartOfLine()) &&
+        SM.getPresumedLineNumber(StmtLoc) !=
+            SM.getPresumedLineNumber(Tok.getLocation()) &&
+        (Tok.isNot(tok::identifier) ||
+         P.getPreprocessor().LookAhead(0).isNot(tok::colon))) {
+      P.Diag(Tok.getLocation(), diag::warn_misleading_indentation) << Kind;
       P.Diag(StmtLoc, diag::note_previous_statement);
     }
   }
index 4b9d45b..8339f21 100644 (file)
@@ -305,3 +305,10 @@ int main(int argc, char* argv[]) {
 fail:;
 }
 
+void f_label(int b) {
+  if (b)
+    return;
+    a:
+  return;
+  goto a;
+}