[PATCH] D71083: [Diagnsotics] Small Improvement on -Wmisleading-indentation
Tyker via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 05:56:28 PST 2019
This revision was automatically updated to reflect the committed changes.
Tyker marked an inline comment as done.
Closed by commit rG9c8cfa09d762: [Diagnsotics] Small Improvement on -Wmisleading-indentation (authored by Tyker).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71083/new/
https://reviews.llvm.org/D71083
Files:
clang/lib/Parse/ParseStmt.cpp
clang/test/Parser/warn-misleading-indentation.cpp
Index: clang/test/Parser/warn-misleading-indentation.cpp
===================================================================
--- clang/test/Parser/warn-misleading-indentation.cpp
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -205,4 +205,23 @@
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
+}
Index: clang/lib/Parse/ParseStmt.cpp
===================================================================
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1201,13 +1201,12 @@
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 @@
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 @@
P.MisleadingIndentationElseLoc = SourceLocation();
return;
}
+ if (Kind == MSK_else)
+ P.MisleadingIndentationElseLoc = SourceLocation();
SourceManager &SM = P.getPreprocessor().getSourceManager();
unsigned PrevColNum = SM.getSpellingColumnNumber(PrevLoc);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71083.233599.patch
Type: text/x-patch
Size: 2479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191212/0b15feec/attachment-0001.bin>
More information about the cfe-commits
mailing list