[clang] 9c8cfa0 - [Diagnsotics] Small Improvement on -Wmisleading-indentation

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 12 05:53:06 PST 2019


Author: Tyker
Date: 2019-12-12T14:52:47+01:00
New Revision: 9c8cfa09d762a307bae55b75b621cbc53f4a3b3b

URL: https://github.com/llvm/llvm-project/commit/9c8cfa09d762a307bae55b75b621cbc53f4a3b3b
DIFF: https://github.com/llvm/llvm-project/commit/9c8cfa09d762a307bae55b75b621cbc53f4a3b3b.diff

LOG: [Diagnsotics] Small Improvement on -Wmisleading-indentation

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xbolva00

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index dc951dc22f55..203f30610ce7 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1201,13 +1201,12 @@ struct MisleadingIndentationChecker {
   SourceLocation PrevLoc;
   unsigned NumDirectives;
   MisleadingStatementKind Kind;
-  bool NeedsChecking;
   bool ShouldSkip;
   MisleadingIndentationChecker(Parser &P, MisleadingStatementKind K,
                                SourceLocation SL)
       : P(P), StmtLoc(SL), PrevLoc(P.getCurToken().getLocation()),
         NumDirectives(P.getPreprocessor().getNumDirectives()), Kind(K),
-        NeedsChecking(true), ShouldSkip(P.getCurToken().is(tok::l_brace)) {
+        ShouldSkip(P.getCurToken().is(tok::l_brace)) {
     if (!P.MisleadingIndentationElseLoc.isInvalid()) {
       StmtLoc = P.MisleadingIndentationElseLoc;
       P.MisleadingIndentationElseLoc = SourceLocation();
@@ -1216,9 +1215,10 @@ struct MisleadingIndentationChecker {
       P.MisleadingIndentationElseLoc = SL;
   }
   void Check() {
-    NeedsChecking = false;
     Token Tok = P.getCurToken();
-    if (ShouldSkip || NumDirectives != P.getPreprocessor().getNumDirectives() ||
+    if (P.getActions().getDiagnostics().isIgnored(
+            diag::warn_misleading_indentation, Tok.getLocation()) ||
+        ShouldSkip || NumDirectives != P.getPreprocessor().getNumDirectives() ||
         Tok.isOneOf(tok::semi, tok::r_brace) || Tok.isAnnotation() ||
         Tok.getLocation().isMacroID() || PrevLoc.isMacroID() ||
         StmtLoc.isMacroID() ||
@@ -1226,6 +1226,8 @@ struct MisleadingIndentationChecker {
       P.MisleadingIndentationElseLoc = SourceLocation();
       return;
     }
+    if (Kind == MSK_else)
+      P.MisleadingIndentationElseLoc = SourceLocation();
 
     SourceManager &SM = P.getPreprocessor().getSourceManager();
     unsigned PrevColNum = SM.getSpellingColumnNumber(PrevLoc);

diff  --git a/clang/test/Parser/warn-misleading-indentation.cpp b/clang/test/Parser/warn-misleading-indentation.cpp
index e5ed8bba93c1..d366db767e67 100644
--- a/clang/test/Parser/warn-misleading-indentation.cpp
+++ b/clang/test/Parser/warn-misleading-indentation.cpp
@@ -205,4 +205,23 @@ void a3(int i) {
     i = 4;
     }
     return;
-}
\ No newline at end of file
+}
+
+void s(int num) {
+    {
+        if (1)
+            return;
+        else
+            return;
+        return;
+    }
+    if (0)
+#ifdef WITH_WARN
+// expected-note at -2 {{here}}
+#endif
+        return;
+        return;
+#ifdef WITH_WARN
+// expected-warning at -2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+}


        


More information about the cfe-commits mailing list